Fe-interview: [vue] watch怎么深度监听对象变化

Created on 16 Jun 2019  ·  3Comments  ·  Source: haizlin/fe-interview

[vue] watch怎么深度监听对象变化

vue

Most helpful comment

deep设置为true 就可以监听到对象的变化

    let vm=new Vue({
        el:"#first",
        data:{msg:{name:'北京'}},
        watch:{

            msg:{
                handler (newMsg,oldMsg){
                    console.log(newMsg);
                },
                immediate:true,
                deep:true
            }
        }
    })

All 3 comments

'a.b.c', 然后直接解析到c那层, 绑定observer

'obj.xx': { handler: function(val) {}, deep:true }

deep设置为true 就可以监听到对象的变化

    let vm=new Vue({
        el:"#first",
        data:{msg:{name:'北京'}},
        watch:{

            msg:{
                handler (newMsg,oldMsg){
                    console.log(newMsg);
                },
                immediate:true,
                deep:true
            }
        }
    })
Was this page helpful?
0 / 5 - 0 ratings