Geek

博客园 首页 新随笔 联系 订阅 管理
<!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>
    <link href="https://cdn.bootcdn.net/ajax/libs/animate.css/2.0/animate.css" rel="stylesheet">

    <style>


    </style>
</head>
<body>
<div id="app">
    count : {{size}}
    <input type="text" v-model="inputValue">
    <button @click="press">press</button>

    <ul>


        <fade>
            <todo-item :content="i"
                       v-for="(i,index) in list"
                       :index="index"
                       :key="index"
                       @delete="deleteChild(index)"></todo-item>
        </fade>

     

    </ul>

</div>

<script>
    Vue.component('fade', {

        template: `
            <transition-group name="fade"
                              appear
                              appear-active-class="animated tada"
                              :duration="{ enter: 200, leave: 200 }"
                              enter-active-class="animated swing"
                              leave-active-class="animated shake"
            >
                <slot></slot>
            </transition-group>
        `
    })

    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>

 

posted on 2020-10-28 18:42  .geek  阅读(178)  评论(0编辑  收藏  举报