zoukankan      html  css  js  c++  java
  • vue 动画过渡 【transition-group标签】

    vue 通过在某一时刻 添加一些样式,实现动画

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    
        <style>
            /*添加的时候*/
            .fade-enter {
                opacity: 0;
            }
    
            .fade-enter-active {
                transition: opacity 3s;
            }
    
            /*移除的时候*/
            .fade-leave-to {
                opacity: 0;
            }
    
            .fade-leave-active {
                transition: opacity .3s;
            }
        </style>
    </head>
    <body>
    <div id="app">
        count : {{size}}
        <input type="text" v-model="inputValue">
        <button @click="press">press</button>
    
        <ul>
            <transition-group name="fade">
    
                <todo-item :content="i"
                           v-for="(i,index) in list"
                           :index="index"
                           :key="index"
                           @delete="deleteChild(index)"></todo-item>
    
            </transition-group>
    
        </ul>
    
    </div>
    
    <script>
    
        let todoItem = {
            props: ['content'],
            template: '<li @click="press">{{content}}</li>',
            methods: {
                press(target) {
                    this.$emit('delete')
                }
            }
        }
        const app = new Vue({
            el: '#app',
            data: {
                list: ['第一', '第二'],
                inputValue: '',
                count: 0
            },
            components: {
                TodoItem: todoItem
            },
            methods: {
                press: function () {
                    // alert("press")
                    this.list.push(app.$data.inputValue)
                    this.inputValue = ''
                },
                deleteChild: function (childNode) {
                    console.log(childNode)
                    this.list.splice(childNode, 1)
                }
            },
            watch: {
                list: function (list, newlist) {
                    this.count = newlist.length
                },
                inputValue: function (oldVal, newVal) {
                    console.log(newVal)
    
                }
            },
            computed: {
                size: {
                    get() {
                        return this.count;
                    },
                    set(value) {
                        console.log(value)
                    }
                }
            }
        })
    
    
    </script>
    
    </body>
    </html>
  • 相关阅读:
    xsos:一个在Linux上阅读SOSReport的工具
    RHEL sosreport
    sosreport -a --report
    环境变量
    读研重要的是要明白你自己要干什么, 不能等导师来告诉你你应该干什么. 研究生的优势在于理论功底深厚, 思维具有穿透力,
    awk sed grep 常用命令
    如何删除文件中的空行
    Vim删除空行
    WPS 2010 页眉下方添加下划线
    Android开发环境搭建
  • 原文地址:https://www.cnblogs.com/lyr-2000/p/13892404.html
Copyright © 2011-2022 走看看