[vue]使用require引用元件時的注意事項

  • 2848
  • 0

https://github.com/vuejs/vue-router/issues/1882

結尾要加上default

 

...

 

若使用require去引用.vue,
需在結尾加上default:

let routes=[
  {
    path:'/dashboard',
    component:require('@/js/components/Dashboard.vue').default
  },
...
]


否則可能會出現以下錯誤訊息:
[Vue warn]: Failed to mount component: template or render function not defined.

若是使用import的話就沒有這個問題:

import dashboard from '@/js/components/Dashboard.vue';

...

let routes=[
  {
    path:'/dashboard',
    component:dashboard
  },
...
]