码迷,mamicode.com
首页 > 其他好文 > 详细

Vue - 过渡 列表过渡

时间:2018-06-14 11:37:10      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:IV   rem   new   rand   获取   button   enter   script   ansi   

列表的进入/离开过渡

<div id="app" class="demo">
    <button @click="add">Add</button>
    <button @click="remove">Remove</button>
    <br>
    <br>
    <transition-group name="list">
        <span v-for="item in items" :key="item" class="list-item">{{item}}</span>
    </transition-group>
</div>
<script>
new Vue({
    el: '#app',
    data: {
        items: [1, 2, 3, 4, 5, 6, 7, 8, 9],
        num: 10
    },
    methods: {
        randomIndex () {
            // 获取不超过数组长度的随机数
            return Math.floor(Math.random() * this.items.length)
        },
        add () {
            this.items.splice(this.randomIndex(), 0, this.num++)
        },
        remove () {
            this.items.splice(this.randomIndex(), 1)
        }
    }
})
</script>
<style>
.list-item{
    margin-right: 10px;
    display: inline-block;
}
.list-enter-active, .list-leave-active{
    transition: all 1s;
}
.list-enter, .list-leva-to{
    opacity: 0;
    transform: translateY(30px);
}
</style>

Vue - 过渡 列表过渡

标签:IV   rem   new   rand   获取   button   enter   script   ansi   

原文地址:https://www.cnblogs.com/xiaobaiv/p/9181240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!