vue使用

router动态引入

安装 syntax-dynamic-import 插件

cnpm install babel-plugin-syntax-dynamic-import –save-dev

修改 build/webpack.base.conf.js,添加 options{}

1
2
3
4
5
6
7
// 新加的options 顺序不能动
test: /\.js$/,
loader: 'babel-loader',
options: {
plugins: ['syntax-dynamic-import']
},
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]

使用

1
2
3
4
5
6
7
{
path: '/home',
name: 'home',
component: () => import('../components/home'),
meta: {
title: '发票查询'
}

页面标题

修改页面标题 ,需要在 new Vue之前 在main.js加入

1
2
3
4
5
6
7
router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
if (to.meta.title) {
document.title = to.meta.title
}
next()
})

router

1
2
3
4
5
6
7
{
path: '/home',
name: 'home',
component: ()=>import('../components/home'),
meta:{
title:'发票查询'
}