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

在onChange事件中不能调用store.update(),会死循环 #115

Open
hyhkjiy opened this issue Aug 19, 2020 · 0 comments
Open

在onChange事件中不能调用store.update(),会死循环 #115

hyhkjiy opened this issue Aug 19, 2020 · 0 comments

Comments

@hyhkjiy
Copy link

hyhkjiy commented Aug 19, 2020

比如有state和stateText两个变量都放在store中:

export default {
  data: {
    state: 0,
    stateText: '未连接'
  }
}

我希望在state的值改变的时候stateText也自动变为相应的文字,所以需要在onChange事件中监听state的变化然后修改stateText的值,但是在修改完成后调用update的时候又因为state的值还没有真正改变所以把修改state的diff又提交了一次,在这种情况下就导致了state的值永远也修改不了。

我想到的解决思路有两种:

  1. 在store里面的值改动完成之后再调用onChange回调方法。
  2. 在onChange回调里面提供修改diff的功能。

为了简单易用且不影响其它参数的修改这里建议使用第一种方式,在实际修改store之后再去调用onChange。

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

1 participant