vue列表过度

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>列表过度</title>
    <script src="./vue.js"></script>
    <style>
        .v-enter,v-leave-to {
            opacity: 0;
        }
        .v-enter-active,v-leave-active {
            transition: opacity 1s;
        }
    </style>
</head>
<body>
<div id="root">
    <transition-group>
    <div v-for="(item,index) of list" :key="item.id">
        {{item.title}}
    </div>
    </transition-group>
    <button @click="handleBtn">add</button>
</div>

<script>
    
    var count = 0;
    var vm=new Vue({
        el:'#root',
        data:{
            list:[]
        },
        methods:{
            handleBtn: function() {
                this.list.push({
                    id: count++,
                    title: 'hello world'
                })
            }
        }
    })
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_19168521/article/details/80944247