vue:监听

59 阅读1分钟
        {{obj}}
    </div>
    <script src="./vue2.6.14.js"></script>
    <script>
        new Vue({
            el: "#app",
            data: function () {
                return {
                    obj: {
                        name: 'zhangsan',
                        age: 20
                    }
                }
            },
            created() {
                setTimeout(() => {
                    this.obj.name = 'lisi'
                    this.obj.age = '22'
                }, 3000);
            },
            watch:{
                obj:{
                    handler(){
                        console.log('你的信息变化了');
                    },
                    deep:true
                }
            }




        })
    </script>