-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Vue.delete & Vue.set 无法触发watch #2036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@gebilaoxiong 大哥,你试试用 |
@gebilaoxiong work well var testVM = new Vue({
el:'#ct',
data: {
name: '测试人员',
info: {
age: 12,
school: '测试学校'
},
frends: [{}]
}
});
testVM.$watch('info', function(n, o) {
alert(n + " " + o);
testVM.$delete('info.age');
}); <div id="ct">
<input type="text" v-model="info.age">{{info.age}}
</div> |
@luckymore 按照他的设计,删除info.age的时候,监控info的watch应该被触发 |
你的使用方式不对吧,确实触发了。 |
@luckymore 我的意思是在代码中操作删除age 但是,貌似你的删除操作也没有生效。 明白吗 |
我好像也遇到过,后来换 vuex 就没继续跟进了 |
这里确实有些不一致,现版本修改对象的结构需要 deep watcher 才会触发: testVM.$watch('info', function() {
console.log('info 的 wather');
}, { deep: true }); 下个版本不需要 deep 也会触发。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
您好,上次拜读您代码的时候还是0.11版本,非常喜欢。最近Vue升级到了1.0X版本,于是又读了一遍
在断点的时候遇到个问题:
按照您的设计:对象和数组中____ob____的dep是用来监控数组结构的,在数组中任何改变数组结构的方法('push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse')都会调用数组的____ob____.dep.notify。按照这个逻辑在对象结构发生变化的时候是不是也会调用对象的____ob____.dep.notify; 不知道是不是我的理解有误,下面的代码没有触发watcher的update。
以下是测试代码:
The text was updated successfully, but these errors were encountered: