Tencent / wepy

小程序组件化开发框架
https://wepyjs.gitee.io/wepy-docs/
Other
22.48k stars 3.05k forks source link

用 vuex mapState 后将 computed 给子组件传值会导致 无限循环 setData #2448

Open yanthink opened 4 years ago

yanthink commented 4 years ago

Description

用了 vuex,然后在 page 里面通过 mapState 设置 computed,最后把 computed 往子组件传值就会导致 setData 无限循环

Environment

Reproduce

page.js

  <template>
    <view>
      <article-content :article="article"></article-content>
    </view>
  </template>

  <script>
    import wepy from '@wepy/core';
    import { mapState, mapActions } from '@wepy/x';
    import store from './vuex';

    wepy.page({
      store,

      computed: {
        ...mapState('articleShow', [
          'article',
        ]),
      },

      methods: {
        ...mapActions('articleShow', [
          'fetchArticle',
        ]),
      },

      onLoad ({ id }) {
        this.fetchArticle(id);
      },
    });
  </script>
  <config>
    {
      usingComponents: {
        'article-content': './components/article-content',
      },
    }
</config>

Observed Results

无限循环 setData article

yanthink commented 4 years ago

看了下源码,好像是这段代码额问题

image

jigsaw-china commented 4 years ago

wepy2.0 vuex这一块 bug太多,还是建议用1.7的

Trgree commented 4 years ago

没有解决么,好多抗啊

shanjixiaboss commented 4 years ago

没有解决么,好多抗啊

是指vuex,还是整个2.0?比之前版本坑好多吗?

akkuan commented 3 years ago

我也碰到这个问题了 找了两天原因还是不行, 一直因为自己代码问题, 直到我今天写了一个空的demo, computed里放mapState。 每打开一次页面 这里面的state就会多被修改一次, 跳转10次这个页面,下次进去会setData mapState的值10次