Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

elementui table组件监听data,不用深度监听?

最近在看elementui table组件的源码,发现

watch: {
    data: {
        immediate: true,
        handler(value) {
            this.store.commit('setData', value);
        }
    }
}

data不是数组类型吗,不加deep: true可以监听到内部数据的变化吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

不加deep: true不能监听到内部数据的变化,但是这和他是不是数组无关,object类型的数据不开启deep同样也监听不到内部数据的变化。

watch中开启deep只是告诉数据,内部数据发生变化的时候,通知这一Watcher,而监听内部数据的可能不止这一个Watcher,比如用于渲染页面的属性,会收集渲染Watcher等,等到属性变化,会触发渲染Watcher,改变页面。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...