D
D
Devero972020-12-10 21:26:21
Vue.js
Devero97, 2020-12-10 21:26:21

Why does it give an error on the server when refreshing the page?

My dynamic page

<template>
<div>
<component 
:is="componentName"
:data="data"
/>
</div>
</template>

<script>
import Card from '@/components/main/pages/Card'
import Post from '@/components/main/pages/Post'
import Tag from '@/components/main/pages/Tag'
export default {
    components: {
        Card,
        Post,
        Tag
    },
    data() {
          return {
            data: '',
            componentName: ''
          }
     },
     async beforeRouteEnter(to, from, next) {
        const store = from.matched[0].instances.default.$store
        const res = await store.dispatch('data/getData', to.params.slug)
        console.log(res);
        next(vm => {
            
            vm.data = res.card
            vm.componentName = res.category;
        })  
     }
}
</script>

Everything works properly, renders the component that is needed. But when updating the page itself, such an error occurs on the server - Cannot read property 'instances' of undefined
What could be wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question