Answer the question
In order to leave comments, you need to log in
How to implement the correct work of the dynamic layout component in vue3?
Where is the mistake?
app.vue
<template>
<component :is="layout">
<router-view/>
</component>
</template>
<script>
export default {
name: 'App',
computed: {
layout() {
const layoutName = this.$route.meta.layout || 'DefaultLayout';
return () => import(`@/layouts/${layoutName}.vue`)
}
},
}
</script>
...
import Home from "../views/Home";
const routes = [
{
path: '',
name: 'Home',
component: Home,
meta: {
layout: () => import('../layouts/DefaultLayout')
}
},
...
Answer the question
In order to leave comments, you need to log in
Don't reinvent the wheel, use nested routes https://router.vuejs.org/guide/essentials/nested-r...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question