繁体   English   中英

为什么当我更改路由时组件不呈现?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM