账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Vue 单文件组件的transitions 怎么挂载钩子函数
    • 2018-08-14 00:00
    • 10
    37
    -1
    <template>
    <div id="item">
        <transition-group name="trans" v-on:enter="enter" v-on:leave="leave" v-on:after-leave="afterLeave">
        <div class="item-list" key="0"  id="item_box" v-bind:class="{'item-nomal':item_show,'item-big':!item_show}">
            <div class="item-main">
                <div class="item-details"  >
                    <p class="item-details-title" >{{ items.title}}</p>
                    <p class="item-details-author" >{{ items.author}}</p>
                    <p class="item-details-journal" >{{ items.journal}}</p>
                </div>
                <div class="item-other" >
                    <div class="item-other-txt">
                        <p class="item-other-time">{{items.time}}</p>
                        <a class="item-other-link"  v-on:click="clickmore()">more>></a>
                    </div>
                </div>
            </div>
            <div class="item-other-abstract"  key="1" id="item_abstract" v-show="!item_show">
                <h4>Abstract</h4>
                <p>{{items.abstract}} </p>
                <ul>
                    <li>bibtex</li>
                    <li>view</li>
                    <li>download</li>
                </ul>
            </div>
        </div>
        </transition-group >
     <transition name="trans">
        <div class="item-other-img">
            <img  v-bind:src="items.img" alt=""  key="2" v-bind:class="{'img-nomal':item_show,'img-big':!item_show}">
        </div>
    </transition>
    </div>
    </template>
    
    <script>
    export default {
    name:'item',
    props: {
        items:{
            title:String,default: 'CS',
            author:String,
            default: 'Name',
            journal:String,
            default: 'AAAI',
            time:String,
            default: '2018',
            img:true,
            },
        },
    methods: {
        clickmore(){ 
            this.item_show=!this.item_show;
        },
        enter(el,done){
            console.log('1');
            done()
        },
        afterLeave(el){
            console.log('1');
        },
        leave(el,done){
            console.log('1');
             done()
        },
    
      },
    data () {
        return {
            item_show:false,
            max_h:0,
            height: 0,
    
        }
    },
    transitions:{
        'trans':{
                      beforeEnter(el) {
           console.log('1');
          },
          enter(el) {
             console.log('1');
          },
          afterEnter(el) {
             console.log('1');
          },
          enterCancelled(el) {
            // handle cancellation
          },
    
          beforeLeave(el) {
            console.log('1');
          },
          leave(el) {
          console.log('1');
          },
          afterLeave(el) {
            console.log('1');
          },
    
    },
    },
    watch: {
        item_show:function()
        {
        }
    },
    
    
    }
    
    </script>
    
    <style lang="less">
    
    
    
    .item-list{width:913px;padding-top: 10px;position: relative;border-bottom: 1px solid #777;float: left; transition: all 1s ease;overflow: hidden;}
    .item-list:hover{ transition:0.8s; background-color:#f9f9f9;}
    .item-big{height: auto;transition: all 1s ease;}
    .item-nomal{ height: 180px;transition: all 1s ease;}
    .item-main{width: 100%;height: 180px;padding-bottom: 0px;}
    .item-details{width: 85%;text-align: left;float: left;margin-left: 10px;height: 180px;}
    .item-details-title{font-size: 28px;    font-weight: 400;
        color: #1f2f3d;}
    .item-details-author{     color: red;   font-size: 16px;
        line-height: 25px;}
    .item-details-journal{     color: red;    font-size: 16px;
        line-height: 25px;}
    .item-other{float: left;}
    .item-other-link{ cursor: pointer;}
    .item-other-txt{float: left;margin-left: 20px;}
    .item-other-txt .item-other-time{height: 100px;}
    .item-other-img{float: left;height: 180px;width: 20%;}
    .img-nomal{    height: 140px;
        width: 140px;
        margin-top: 10px;
        margin-left: 10px;transition:.8s}
    .img-big{ height: 180px;
        width: 180px;
        margin-top: 10px;
        margin-left: 10px; transition:.8s}
    .item-other-abstract{ margin-left: auto;margin-right: auto;height: auto;width: 93%;}
    .item-other-abstract h4{font-weight: 600;
            color: #2c3e50;font-size: 18px;margin-bottom: 5px;margin-top: 5px;}
    .item-other-abstract p{ text-align: left;overflow: hidden;}
    .item-other-abstract ul{ text-align: right;height: 20px;}
    .item-other-abstract ul li{float: right;padding-left: 10px;padding-right: 10px;cursor: pointer;}
    .item-other-abstract ul li+li{ border-right: 2px solid #777;}
    .item-other-abstract ul li:hover{ color: rgb(134, 138, 127);}
    .item-tran-leave-active{transition:1s cubic-bezier(1.0, 0.5, 0.8, 1.0);}
    .item-tran-enter-active{transition:1s cubic-bezier(1.0, 0.5, 0.8, 1.0);}
    .item-list-transition{overflow: hidden;transition:1s cubic-bezier(1.0, 0.5, 0.8, 1.0); }
    .trans-enter-active,.trans-leave-active{transition:1s cubic-bezier(1.0, 0.5, 0.8, 1.0);}
    </style>
    

    都没什么反应。。

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • -1
    • ︶ㄣ随гゞ枫 普通会员 1楼

      在 Vue 中,你可以在单文件组件中使用钩子函数来挂载 transitions。以下是详细的步骤:

      1. 在你的 Vue 项目中,找到你想要在其中添加 transitions 的组件。

      2. 在该组件中,使用 Vue 的 defineComponent 方法来创建一个新的组件。

      3. 在 new Vue 组件中,添加一个钩子函数,该函数将在组件挂载后调用。

      以下是一个简单的示例:

      javascript export default { extends: 'vue', props: { // 其他 prop... }, mounted() { // 在组件挂载后调用的钩子函数... }, beforeDestroy() { // 在组件即将销毁时调用的钩子函数... } }

      在这个例子中,我们定义了一个在组件挂载后调用的钩子函数。这个函数可以在你需要使用 transitions 的任何地方调用。

      注意:在 Vue 3 中,你需要使用 new ExportDefault from 'vue-class-component'。这个导入可以使你的过渡挂载在组件实例上。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部