Created
December 12, 2020 14:32
-
-
Save NovoManu/9ccd6c1c6de3ff294106e024f1aeceed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<component :is="layout"> | |
<slot /> | |
</component> | |
</template> | |
<script> | |
import AppLayoutDefault from './AppLayoutDefault' | |
import { markRaw, watch } from 'vue' | |
import { useRoute } from 'vue-router' | |
export default { | |
name: 'AppLayout', | |
setup() { | |
const layout = markRaw(AppLayoutDefault) | |
const route = useRoute() | |
watch( | |
() => route.meta, | |
async meta => { | |
try { | |
const component = await import(`@/layouts/${meta.layout}.vue`) | |
layout.value = component?.default || AppLayoutDefault | |
} catch (e) { | |
layout.value = AppLayoutDefault | |
} | |
}, | |
{ immediate: true } | |
) | |
return { layout } | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried this code but don't worked me. Some changes i did and code is work.