这种报错原因是 vue有两种形式的代码 compiler(模板)模式和runtime模式(运行时),vue模块的package.json的main字段默认为runtime模式, 指向了"dist/vue.runtime.common.js"位置。
- compiler模式的:
new Vue({
el: '#app',
template: '<App/>',
components: { App }
})
这种写法就是导致上述报错原因
- runtime模式
new Vue({
router,
render: h => h(App)
}).$mount("#app")
runtime模式 就可以解决这个问腿
如果是升级原因导致的解决办法如下
- 方法一: vue.config.js
configureWebpack: {
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
- 方法二 : 针对以前老版本的vue
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}