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

[Wepy 2.0] computed 无法检测来自 mapState 元素变化 #2487

Open
hdsuperman opened this issue Nov 19, 2019 · 3 comments
Open

[Wepy 2.0] computed 无法检测来自 mapState 元素变化 #2487

hdsuperman opened this issue Nov 19, 2019 · 3 comments

Comments

@hdsuperman
Copy link

#1768 Description

[问题描述:computed 无法检测 mapState 元素变化]

Environment

  • Platform: [开发者工具]
  • "@wepy/core": "^2.0.0-alpha.9",
  • "@wepy/redux": "^2.0.1",
  • "redux": "^4.0.4",
  • "redux-actions": "^2.6.5",
  • "redux-saga": "^1.1.3",

Reproduce

  computed: {
    ...mapState({
      article: state => state.article.article,
      likeArticleList: state => state.article.likeArticleList,
    }),

    // 无法 computed 来自 computed 的元素
    isLiker() {
      let is = false;
      if(this.article && this.likeArticleList) {
        is = this.likeArticleList.indexOf(this.article.articleId) !== -1;
      }
      return is;
    },
}

在reducer 或者组件的methods 可以检测到变化,但是当computed 的对象是两个来自 mapState 的元素时,无法检测到变化

Observed Results

isLiker 值一直是 false;只在组件创建的时候计算过一次

Expected Results

isLiker 值根据mapState 元素变化动态计算结果

@hdsuperman
Copy link
Author

临时解决办法:
在组件的 onShow 中启动 setInterval, 定时2 秒计算对应值

@hdsuperman hdsuperman changed the title computed 无法检测 mapState 元素变化 computed 无法检测来自 mapState 元素变化 Nov 19, 2019
@hdsuperman hdsuperman changed the title computed 无法检测来自 mapState 元素变化 [Wepy 2.0] computed 无法检测来自 mapState 元素变化 Nov 19, 2019
@HELLC--
Copy link

HELLC-- commented Nov 26, 2019

为何不放在store中去计算,getters抛出来就行了

@chenillen
Copy link
Contributor

为何不放在store中去计算,getters抛出来就行了

getters 貌似用不了。參看 issue#2411

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

3 participants