-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppLayout.vue
50 lines (49 loc) · 1.23 KB
/
AppLayout.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<template>
<component :is="currentLayout" />
</template>
<script>
export default {
name: 'AppLayout',
props: {
layout: {
type: String,
default: 'default'
},
loading: {
type: String,
default: null
},
prefix: {
type: String,
default: ''
},
path: {
type: String,
default: 'layouts'
}
},
data () {
return {
layoutName: 'default'
}
},
computed: {
currentLayout () {
if (!this.layoutName) return
const ln = this.prefix + this.layoutName
return () => import(`./${this.path}/${ln}.vue` /* webpackChunkName: "layout-[request]" */)
}
},
watch: {
'$route': {
immediate: true,
handler (route) {
const newLayout = route.meta.layout
if (!newLayout && !this.$route.name) { this.layoutName = this.loading; return }
if (!newLayout) { this.layoutName = this.layout || 'default'; return }
this.layoutName = newLayout
}
}
}
}
</script>