两种方法:
1.运用require直接写
export const constantRouterMap = [
{path:'/',component:resolve => require(['../pages/home.vue'], resolve),
children:[
{path:'/app',component:resolve => require(['../pages/app.vue'], resolve),name:'app'},
{path:'/web',component:resolve => require(['../pages/web.vue'], resolve),name:'web'}
]
},
// { path: '*',component:"Error"}
]
2.运用import,这也是官方文档的写法
const Home = () => import('../pages/home.vue')
const App = () => import('../pages/app.vue')
const Web = () => import('../pages/web.vue')
export const constantRouterMap = [
{path:'/',component:Home,
children:[
{path:'/app',component:App},
{path:'/web',component:Web}
]
},
]
import和require的区别是什么呢?
require是node.js (common.js)的语法,而import是ES6的语法;require引入的值是一个值得拷贝,而ES6引入一个值,引入的是这个值的引用