A full-featured Webpack + extend layout + vue-loader setup with hot reload, linting, testing & css extraction.
Using vue-extend-layout package, inspired in layouts of the Nuxt.js
This template is Vue 2.0 compatible
- For template webpack: common questions specific to this template are answered and each part is described in greater detail
- For Vue 2.0: general information about how to work with Vue, not specific to this template
This is a project template for vue-cli. It is recommended to use npm 3+ for a more efficient dependency tree.
$ npm install -g vue-cli
$ vue init ktquez/layout my-project
$ cd my-project
$ npm install
$ npm run dev
If port 8080 is already in use on your machine you must change the port number in /config/index.js. Otherwise npm run dev will fail.
By default, there are 2 layout components in the directory layouts/
:
- layouts/default.vue => Is the default application extend layout
- layouts/error.vue => This is the layout for error page
Both are already configured in the route file For example:
...
export default new Router({
mode: 'history',
base: '/',
routes: [
{
path: '/',
name: 'Hello',
component: () => import('@/pages/Hello'),
// Setting layout when default, is optional, no need to set.
},
{
path: '*',
name: 'Error',
meta: {
layout: 'error' // error layout for route mismatch
}
}
]
})
To create a layout you just need to create a component within the layouts directory and name that component.
For example:
layouts/myCustomLayoutLogin.vue
<template>
<div>
<router-view />
</div>
</template>
<script>
export default {
name: 'myCustomLayoutLogin' // id of the layout
}
</script>
<style>
/* your style */
</style>
And to extend this layout in any the desired route, simply include the property layout: myCustomLayoutLogin
in meta object of the route.
{
path: '/login',
name: 'Login',
component: () => import('@/pages/Login'),
meta: {
layout: 'myCustomLayoutLogin' // name of the layout
}
}
Attention: The value of the layout
property must be the same as the name of the myCustomLayoutLogin
component.
- In development
- Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found.
- Fork repository, make changes, add your name and link in the contributors session readme.md
- Send a pull request
If you want a faster communication, check out my blog ktquez.com or find me on Twitter @ktquez
Thank you for using!