wepy
wepy copied to clipboard
用 vuex mapState 后将 computed 给子组件传值会导致 无限循环 setData
Description
用了 vuex,然后在 page 里面通过 mapState 设置 computed,最后把 computed 往子组件传值就会导致 setData 无限循环
Environment
- Platform: 开发者工具
- Platform version: 1.02.1907300
- wepy-cli version: 2.0.0-alpha.20
- wepy version: 0.02
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
看了下源码,好像是这段代码额问题
wepy2.0 vuex这一块 bug太多,还是建议用1.7的
没有解决么,好多抗啊
没有解决么,好多抗啊
是指vuex,还是整个2.0?比之前版本坑好多吗?
我也碰到这个问题了 找了两天原因还是不行, 一直因为自己代码问题, 直到我今天写了一个空的demo, computed里放mapState。 每打开一次页面 这里面的state就会多被修改一次, 跳转10次这个页面,下次进去会setData mapState的值10次