vue5-侦听器

 

watch侦听属性数据变动

<!DOCTYPE html>
<html>
    <head>
        
        <meta charset="utf-8">
        <title>vue1</title>
        <script src="vue.js"></script>
        <link rel="stylesheet" type="text/css" href="vue.css">
    
    </head>
    <body>
        
        
        <div id="app">

            <div>
                <input type="text" v-model="msg">
                <button @click="submit">submit</button>
                <ul>
                    <li v-for="item of list">{{item}}</li>
                </ul>
            </div>


        </div>    
        
        
        <script>
            var app=new Vue({
                el:"#app",
                data:{
                    msg:'',
                    list:[],               
                },
                methods:{
                    submit:function(){
                        this.list.push(this.msg),
                        this.msg=""
                    }
                },
                watch:{
                    list(){
                        console.log(this.list.length)
                    }
                    

                }
 
                
            })        
        </script>
    </body>
</html>

 

posted @ 2020-04-03 14:48  JinweiChang  阅读(114)  评论(0编辑  收藏  举报