Vue-You are using the runtime-only build of Vue where the template compiler is not available

一、出错原因

1.vue-cli脚手架的升级问题,报错:
You are using the runtime-only build of Vue where the template compiler is not available
2.原因
vue有两种形式的代码 分别是compiler(模板)模式和runtime模式(运行时),vue模块的package.json的main字段默认为runtime模式, 指向了"dist/vue.runtime.common.js"位置
在main.js文件中,初始化vue是compiler模式的,因此出现上面的报错信息。

  el: '#app',
  router: router,
  store: store,
  template: '<App/>',
  components: { App }
})

3.解决方法
3.1解法一:将mian.js中的代码修改:

  router,
  store,
  render: h => h(App)
}).$mount("#app")

3.2解法二:vue.config.js文件加上webpack的配置:

    resolve: {
      alias: {
        'vue$': 'vue/dist/vue.esm.js' 
      }
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。