0.0.1-alpha.8 • Published 2 years ago
vue-layouter v0.0.1-alpha.8
vue-layouter
This is a vue plugin that provides extended layouts for route component.
Installation
npm install vue-layouter
Quickstart
Create layout component
Create a directory called
layouts/
inside the main directory of your application.Inside the
layouts/
directory create a layout calleddefault.vue
, for example:src/layouts/default.vue
.
<template>
<div class="container">
<div class="header">header</div>
<div class="main">
<router-view />
</div>
<div class="footer">footer</div>
</div>
</template>
Create the layouter instance
Define some layouts, Each route should map to a component。
Create the layouer instance and pass the
layouts
option.Mount the layout instance to the vue instance.
import Vue from 'vue'
import VueLayouter from 'vue-layouter'
import router from './router'
import App from './App.vue'
import DefaultLayout from '@/layouts/default.vue'
Vue.use(VueLayouter)
const layouter = new VueLayouter({
layouts: [
{
name: 'defaultLayout',
component: DefaultLayout
}
]
})
new Vue({
router,
layouter,
render: h => h(App)
}).$mount('#app')
Render layout
Create an instance of the
layouter-view
component in thesrc/App.vue
file.The matched layout components will be rendered here.
<template>
<layouter-view />
</template>
- Extend this layout in any desired route, simply include the property
layout: auth
in meta object of the route.
import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import Home from '../views/Home.vue'
import Data from '../views/Data.vue'
Vue.use(VueRouter)
export const routes = [
{
path: '/home',
name: 'Home',
component: Home,
meta: {
layout: 'defaultLayout'
}
}, {
path: '/data',
name: 'Data',
component: Data,
meta: {
layout: 'defaultLayout'
}
},
]
const router = new VueRouter({
routes
})
export default router
0.0.1-alpha.9
1 year ago
0.0.1-alpha.6
2 years ago
0.0.1-alpha.4
2 years ago
0.0.1-alpha.5
2 years ago
0.0.1-alpha.2
2 years ago
0.0.1-alpha.3
2 years ago
0.0.1-alpha.8
2 years ago
0.0.1-alpha.1
2 years ago
0.0.1-alpha.0
2 years ago