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

computed和watch有冲突 #11

Closed
githublyp opened this issue Nov 25, 2018 · 11 comments
Closed

computed和watch有冲突 #11

githublyp opened this issue Nov 25, 2018 · 11 comments
Labels
enhancement New feature or request

Comments

@githublyp
Copy link

单独使用watch就可以,两个一起使用就有问题

@wuhy
Copy link
Collaborator

wuhy commented Nov 26, 2018

@githublyp 可以具体描述下问题是什么吗?然后你可以跟另外你提的问题,一并再看下,不知道那个问题跟你这个问题是否有一定关联性

@githublyp githublyp reopened this Nov 28, 2018
@githublyp
Copy link
Author

watch调用两次
watch: {
userInfo: {
handler() {
// 当用户登录完后请求业务逻辑
this.userInfo.uid && this.getUserInfo()
},
deep: true
}
},

@wuhy
Copy link
Collaborator

wuhy commented Nov 29, 2018

@githublyp 没太懂,你这里描述跟标题描述 computed 和 watch 使用冲突有什么直接关系吗?可以具体点描述下你的现象和问题吗?还有 watch 调用两次,具体是做了什么事情触发了两次了?

@githublyp
Copy link
Author

computed 和 watch 使用冲突,这个是由于computed未重新计算引起的,已经好了;
就是我在watch内:
image

@wuhy
Copy link
Collaborator

wuhy commented Nov 29, 2018

@githublyp userInfo 什么时候设置的,具体怎么设置修改的?是你在外部发起异步请求,更新 store userInfo,然后 watch 这里 handler 触发了两次?然后还有个问题,为啥watch handler 里要手动触发生命周期钩子,这个钩子方法是不应该开发者自己去触发调用的

@githublyp
Copy link
Author

userInfo 在外部发起异步请求,更新 store userInfo,然后 watch 这里 handler 触发了两次;

@wuhy
Copy link
Collaborator

wuhy commented Nov 29, 2018

userInfo 在外部发起异步请求,更新 store userInfo,然后 watch 这里 handler 触发了两次;

我这边看下能不能复现你的问题

@wuhy
Copy link
Collaborator

wuhy commented Nov 30, 2018

@githublyp 我这边还是不能复现你说的问题,如果方便的话,可以给下能复现你这个问题的代码示例,谢谢~

@githublyp
Copy link
Author

这是reducer:
image
异步更新了:
SET_STATE_STATUS
SET_STATE_USERINFO

不知道是不是redux的问题

@wuhy
Copy link
Collaborator

wuhy commented Dec 1, 2018

这是reducer:
image
异步更新了:
SET_STATE_STATUS
SET_STATE_USERINFO

不知道是不是redux的问题

大概知道什么问题了,目前实现机制是只要 store 有变化会把所有依赖的 computed props 都重新触发一次计算,导致你这边触发了两次,我这边看下做下优化吧。

@wuhy wuhy added the enhancement New feature or request label Dec 1, 2018
@wuhy
Copy link
Collaborator

wuhy commented Dec 3, 2018

@githublyp 你可以更新到最新 0.4.0-beta.3 看下这里问题,这里做了下优化,具体修改逻辑可以看关联的 commit 记录,我先把这个 issue 关了,有问题再 open~

@wuhy wuhy closed this as completed Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants