![](/img/trans.png)
[英]React js, why doesn't my component re-render when I change the value of open?
[英]Why component doesn't render when I change the route?
我有一个模板,并且有一个组件:
<super-visor
v-if="!top10ModeActivated"
v-for="cart in getCarts(index + 1)"
:cart="cart"
:key="cart.position"
></super-visor>
如您所见,该组件在top10ModeActivated
仅为false
时呈现;
computed: {
top10ModeActivated() {
return this.$store.state.moduleSearch.top10ModeActivated;
},
}
我将debugger
放在top10ModeActivated
,它仅在组件第一次呈现时才起作用。 所以我看到我的组件,只有当我刷新页面而不是当我更改路由时。
任何人都可以帮助我并描述我如何解决这个问题吗? 因为我是 VueJS 的新手。
使用方法,因为计算的属性是缓存的。 见下文:
methods: {
top10ModeActivated() {
return this.$store.state.moduleSearch.top10ModeActivated;
},
}
和
<super-visor
v-if="!top10ModeActivated()"
v-for="cart in getCarts(index + 1)"
:cart="cart"
:key="cart.position"
></super-visor>
直接从计算属性访问存储状态不会使其反应。 改用吸气剂。 创建一个返回 top10ModeActivated 的 Vuex getter,然后在计算属性中调用该 getter 以使其具有响应性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.