33.动画-v-for的列表过度

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=adge">
    <title>Document</title>
    <script src="vue.js"></script>
    <style>
        .list-enter,
        .list-leave-to {
            opacity: 0;
            transform: translateY(10px);
        }

        .list-enter-active,
        .list-leave-active {
            transition: all 0.3s ease;
        }
        .v-move{
            transition: all 0.8s ease;
        }
        .v-leave-active{
            position: absolute;
        }
    </style>
</head>
<body>
    <div id="app">
        <input type="text" v-model="txt" @keyup.enter="add">
        <!-- 这里的name作用是当有多个想要不同过度效果时,在style中,可以用name开头来更好区分设置 -->
        <transition-group tag="ul" name="list">
            <li v-for="(item, i) in list" :key="i">{{item}}</li>
        </transition-group>
    </div>
</body>
<script>
    // 创建 Vue 实例,得到 ViewModel
    var vm = new Vue({
        el: '#app',
        data: {
            txt: '',
            list: [1, 2, 3, 4]
        },
        methods: {
            add() {
                this.list.push(this.txt);
                this.txt = '';
            }
        }
    });
</script>
</html>

 

posted @ 2021-03-13 18:25  种太阳  阅读(18)  评论(0编辑  收藏  举报