Back

vue - 在router中引入 component的时候,如果是require ,记得要 在尾巴上加上 .default

发布时间: 2021-01-13 00:48:00

参考:  https://github.com/vuejs/vue-router/issues/713

使用了新的router写法后, 总是发现报错, 

Failed to mount component: template or render function not defined. (found in root instance)

原来是新的写法, 需要这样写才行: (说到底,还是需要 es 基本功扎实才行)

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [
    {   
      path: '/',
      // 这里default 不能省略
      component: require('@/components/calculators/Index').default
    },  
    {   
      path: '/topologies',
      component: require('@/components/topologies/Index').default
    },  
    {   
      path: '/databases',
      component: require('@/components/databases/Index').default
    },  
    {   
      path: '*',
      redirect: '/' 
    }   
  ]
})

Back