You are using the runtime-only build of Vue where the template compiler is not available
2024-04-10 13:20:14  阅读数 1415
image.png

原因分析:vue有两种形式的代码 compiler(模板)模式和runtime模式(运行时),vue模块的package.json的main字段默认为runtime模式, 指向了"dist/vue.runtime.common.js"位置
解决方法一、
报错后main.js代码:
import App from './App'
import router from './router'

const app = new Vue({
    el: '#app',
    router,
})
app.$mount()

解决方法:

new Vue({
    router,
    render: h=>h(App)
}).$mount('#app')

解决方法二:
webpack配置文件中别名配置添加
'vue$': 'vue/dist/vue.esm.js',指定文件位置

resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
    }
  },