问题描述
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available
解决方案
在vue项目下新建一个vue.config.js 文件内容为
module.exports = {
//Solution For Issue: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.
runtimeCompiler: true
}
原因分析
在项目配置的时候,默认 npm 包导出的是运行时构建,即 runtime 版本,不支持编译 template 模板。 vue在初始化项目配置的时候,有两个运行时版本:Compiler版本、runtime版本。 主要区别在于:
- Compiler 版本: 可以对 template 模板内容进行编译。
- Runtime 版本: 使用 vue-loader 加载.vue 文件(组件文件)时,webpack 在打包过程中对模板进行了渲染。 加载更快。