前提:
在webpack搭建的项目中通过npm install vue --save
引入vue,并书写vue代码时报错。
报错内容:
bundle.js:1310 [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
原因:
webpack中引入vue有两中模式(默认第一种)
- runtime-only
- runtime-compiler
其中第一种不允许使用template,但是vue中不可能不使用template,至少小编暂时内有遇到过,所以需要通过修改webpack.config.js
中的配置来改变为第二种。
解决方案:
在webpack.config.js
中添加如下配置:
module.exports = {
resolve:{
//alias : 别名
alias:{
'vue$':'vue/dist/vue.esm.js'
}
}
}
vue/dist/vue.esm.js
意思是 node-moules---->vue—>dist—>vue.esm.js