vue.js - vuex设置this.$store.dispatch更新没有同步到组件created(){}方法里面
本文介绍了vue.js - vuex设置this.$store.dispatch更新没有同步到组件created(){}方法里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如题,因为我在组件create里面获取不到值,请问怎么才能获取更新后的vuex state值
this.$store.dispatch('setText','jj');
console.log(this.$store.state.text);//这里打印的是jj
const store = new Vuex.Store({
state:{
wxInfo:{},
text:'ss'
},
...
computed:{
...mapState([
'wxInfo',
'text'
])
},
created(){
console.log(this.text)//但是在组件这里打印的却是 ss
...
解决方案
用watch观察, 或者用computed计算属性
这篇关于vue.js - vuex设置this.$store.dispatch更新没有同步到组件created(){}方法里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文