列表过渡

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="zh">
<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 of list" :key="item.id">
                {{ item.title }}
            </div>
        </transition-group>
        <button @click="handleBtnClick">Add</button>
    </div> 
    <script>
    var count = 0;
    new Vue({ 
        el: "#root", 
        data: {
            list: []
        },
        methods: {
            handleBtnClick: function() {
                this.list.push({
                    id: count++,
                    title: 'hello world'
                })
            }
        }
    })
    </script>
</body>
</html>