Vue中使用Vuex获取多个state状态的4种写法
Vue中使用Vuex获取多个state状态的3种写法写法①computed: {count () {return this.$store.state.count},count1 () {return this.$store.state.count1}}写法②computed: mapState(['count','count1'])写法③computed: {...mapState(
·
Vue中使用Vuex获取多个state状态的4种写法
写法①(初级)
computed: {
count () {
return this.$store.state.count
},
count1 () {
return this.$store.state.count1
}
}
写法②(原理级)
computed: mapState({
count: state => state.count,
count1: state => state.count1,
// 官网
// countAlias是个变量,并把count的值赋给它
countAlias: 'count',
// countPlusLoaclState是个方法,可在里面写计算操作并会返回计算后的值,并且可通过this获取data()局部数据的值
countPlusLoaclState (state) {
return state.count + this.num
}
})
写法③(中级)
computed: mapState([
'count',
'count1'
])
写法④(高级)
computed: {
...mapState([
'count',
'count1'
])
}
更多推荐
已为社区贡献5条内容
所有评论(0)