zoukankan      html  css  js  c++  java
  • 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>
    </head>
    <body>
        <div id="app">
            count : {{size}}
            <input type="text" v-model="inputValue">
            <button @click="press">press</button>
            <ul>
               <todo-item :content="i"
                          v-for="(i,index) in list"
                          :index="index"
                          @delete="deleteChild(index)"></todo-item>
            </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>
  • 相关阅读:
    智能指针之 auto_ptr
    UML在线绘图
    inline使用
    工作随笔—2017-12-12
    链表排序
    转——浅谈如何提高服务器并发处理能力
    使用re开发python计算器
    Linux-centos7下python3 环境设置
    C语言中的static 详细分析
    pycharm import pygame 出现报错:No module named 'pygame'
  • 原文地址:https://www.cnblogs.com/lyr-2000/p/13892207.html
Copyright © 2011-2022 走看看