Skip to content
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

watch 不能监听 computed 对象中的内容 #318

Closed
RORlcl opened this issue Aug 9, 2017 · 2 comments
Closed

watch 不能监听 computed 对象中的内容 #318

RORlcl opened this issue Aug 9, 2017 · 2 comments

Comments

@RORlcl
Copy link

RORlcl commented Aug 9, 2017

你好作者:
我们知道现在 watch 能够监听 props 和 data中的状态变化, 求对computed监听的实现, 这对业务实现有太大的帮助了。

另外还有一个bug: watch对 wepy-redux中的 @connect 的监听会触发两次
@connect({
stateNum (state) {
return state.counter.num
},
asyncNum (state) {
return state.counter.asyncNum
}
})

watch = {
stateNum (val, oldval) {
//这里的代码会被执行两次
console.log(val)
}
}

@Gcaufy
Copy link
Collaborator

Gcaufy commented Aug 14, 2017

这是两个问题。

  1. 可以在computed中赋值data实现watch吧。
  2. 刚测试了,的确会触发两次,但是是正常的,demo只有counter1和counter2, counter1的stateNum变化后,会同步改变counter2的stateNum,所以会触发两次,你试着console.log(this)看看。

@Gcaufy Gcaufy closed this as completed Aug 14, 2017
Gcaufy added a commit that referenced this issue Aug 24, 2017
@Gcaufy
Copy link
Collaborator

Gcaufy commented Aug 24, 2017

@RORlcl 上面的commit可以让watch能监听到computed的改变

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants