Vue-router 裏 import 動態導入模塊報錯

router 裏 import 報錯

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

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'layout',
      component: () => import('@/layout/Index')
    }
  ]
})

如果沒有安裝babel-plugin-syntax-dynamic-import插件,並在.babelrc中引入此插件,那麼就會報錯。這是 webpack 動態導入模塊的設置。

{
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ],
    "syntax-dynamic-import"
  ]
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章