简而言之:当动态导入这样的组件时:
var path = '/views/frontend/Study.vue'
const Component = await import(path)
我收到以下错误:
关键依赖项:依赖项的请求是一个表达式
但是如果参数是字符串,则为const Component = await import('/views/frontend/Study.vue')
它工作正常
webpack版本:3.8.1
在。babelrc中,我正在使用syntax-dynamic-import
插件。
更多详细信息:如果您想查看整个图片,这是更多代码...
在Vue路由器中
createView = (path)=> ()=> import('../components/prefetcher').then(m=>m.default(path))
{ path: '/study',
name: 'study',
component: createView('path/to/my/component')
}
prefetcher.js(上面的createView
函数调用导入的内容)
export default async function createView (path) {
const Component = await import(path) // <<<< works fine when using '/path/to/my/component'
asyncData ({ store }) {
store.dispatch("SOME_ACTION")
},
render (h) {
return h(Component.default, { props: { type:extraData.type }})
}
}
更新:幸运地找到了这张票:https://github.com/airbnb/babel-plugin-dynamic-import-node/issues/90