Vue中的列表过渡

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Vue中的列表过渡</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <style type="text/css">
            .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}}————{{item}}
                </div>
            </transition-group>
            <button @click="handleBtnClick">Add</button>
        </div>
        <script type="text/javascript">
            let count = 0
            var rm = new Vue({
                el: '#root',
                data: {
                    list: []
                },
                methods: {
                    handleBtnClick() {
                        this.list.push({
                            id: count++,
                            title: 'Harold'
                        })
                    }
                }
            })
        </script>
    </body>

</html>

 

posted @ 2019-10-31 18:18  嘆世殘者——華帥  阅读(131)  评论(0编辑  收藏  举报