简体   繁体   English

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

[英]Why component doesn't render when I change the route?

I have a template, and there is a component:我有一个模板,并且有一个组件:

        <super-visor
            v-if="!top10ModeActivated"
            v-for="cart in getCarts(index + 1)"
            :cart="cart"
            :key="cart.position"
        ></super-visor>

As you can see, this component renders when top10ModeActivated is only false ;如您所见,该组件在top10ModeActivated仅为false时呈现;

   computed: {
        top10ModeActivated() {
            return this.$store.state.moduleSearch.top10ModeActivated;
        },
   }

I put debugger to top10ModeActivated and it works only when component renders only for the first time.我将debugger放在top10ModeActivated ,它仅在组件第一次呈现时才起作用。 So I see my component, only when I refresh the page but not when I change the route.所以我看到我的组件,只有当我刷新页面而不是当我更改路由时。

Can anybody help me and describe me how I can fix this?任何人都可以帮助我并描述我如何解决这个问题吗? Because I'm new to VueJS.因为我是 VueJS 的新手。

Use methods because computed properties are cached .使用方法,因为计算的属性是缓存的 See below:见下文:

   methods: {
        top10ModeActivated() {
            return this.$store.state.moduleSearch.top10ModeActivated;
        },
   }

and

        <super-visor
            v-if="!top10ModeActivated()"
            v-for="cart in getCarts(index + 1)"
            :cart="cart"
            :key="cart.position"
        ></super-visor>

Accessing store state directly from computed property doesn't make it reactive.直接从计算属性访问存储状态不会使其反应。 Use getters instead.改用吸气剂。 Create a Vuex getter which would return top10ModeActivated and then call that getter in a computed property to have it reactive.创建一个返回 top10ModeActivated 的 Vuex getter,然后在计算属性中调用该 getter 以使其具有响应性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React js,为什么在更改open的值时我的组件不重新渲染? - React js, why doesn't my component re-render when I change the value of open? 当我更改其状态时,React 组件不会呈现 - React component doesn't render when I change its state 如何在 NUXT 2 上渲染一个不会在路由更改时破坏的独立组件 - How do I render a standalone component on NUXT 2 which doesn't destroy on route change 当我更改父组件 state 时,为什么我的 React 子组件没有获取值(重新渲染)? - Why doesn't my React child component get value (re-render) when I change the parent state? 我测试时组件未呈现 - Component doesn't render when I test 为什么更改 state 时我的功能组件没有重新渲染? (反应) - Why my functional component doesn't re-render when change state? (react) functions props 更改不会发生子组件渲染为什么? - functions props change doesn't occurs child component render why? 当组件完成渲染后,更改角度2中的路径 - when component complete render then change route in angular 2 当反应路由器路由更改时,class 组件不会重新渲染 - class component doesn't re-render when react router route changes 路由匹配时,React Router不显示组件(但渲染有效) - React Router doesn't display component when route is matched (but render works)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM