目标
了解vuex在uni-app项目中的缺陷及解决方案
注意事项
小程序端模版不支持$store.xxx写法:如
在模版中不支持$store.state.username访问方式,只能使用辅助函数来提供数据
<view>{{$store.state.username}}</view>
解决方案
通过computed计算出新的变量在当前页面使用
computed:{
...mapState(['username')
}
<view>{{username}}</view>