vue小白一枚来求解,代码是这样的
组件.vue
<template>
<div class="top-ad-section" v-bind:class="{ show: isShowAdStatus }"></div>
</template>
<script>
export default {
mounted() {
setTimeout(() => {
console.log(this.$store.getters.getTopAdStatus, 'before lllll');
this.$store.dispatch('toggleTopAd');
console.log(this.$store.getters.getTopAdStatus, 'after');
}, 200);
},
computed: {
isShowAdStatus() {
return this.$store.getters.getTopAdStatus;
}
}
};
</script>
这段代码要实现的功能是:
在组件加载200ms后改变store中的state的值,使用this.$store.dispatch('toggleTopAd')来改变,这个值可以用this.$store.getters.getTopAdStatus取到,这时候打印出的值是正确的state里的值,可是并没有体现在视图里,不知道是哪里写的有问题了
小白一枚,求大神指点。
以前写react的时候主要用mobx做状态管理,感觉vuex的状态管理至少在形式上是跟redux更接近的?