问题描述
router-view
渲染空白,控制台报错Failed to mount component: template or render function not defined
。并且使用了路由懒加载。
问题原因
路由懒加载错误,路由的component接受的是一个函数
问题解决
调整component参数即可
例:
//直接用变量
const Foo = () => import('./Foo.vue')
const router = new VueRouter({
routes: [
{ path: '/foo', component: Foo }
]
})
//用函数
const getComponent = (name) => () =>
import(`@/views/${name}.vue`)
const router = new VueRouter({
routes: [
{ path: '/home', component: getComponent("Home")}
]
})