vue.js - Vue-CLI 组件错误:您正在使用仅运行时构建的 Vue,其中模板编译器不可用
问题描述
VueJS 新手,正在阅读教程。这是我做的步骤
- 使用 VUE CLI 创建项目
尝试使用此代码创建组件。
var data = { items: [{ text: 'Bananas', checked: true }, { text: 'Apples', checked: false } ], title: 'My Shopping List', newItem: '' }; Vue.component('items-component', { data: function () { return data; }, template: ` <div class="blog-post"> <span>sample</span> </div> ` });
将此添加到 App.vue 模板部分。
<items-component></items-component>
但是我收到了这个错误
[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.
问题
有没有一种方法可以在 Vue Cli 项目中在一个文件中创建多个组件,或者多个文件是创建组件的唯一方法?
使用 CLI 手动编辑 webpack 是一个不错的选择吗?如果是这样,是否有任何好的链接。
请告诉我
解决方案
我的项目也有同样的错误。我通过以下方式解决了它:
- 创建一个新文件:
vue.config.js
并补充说:
module.exports = { runtimeCompiler: true }
关于您的问题,即使我可能无法给出最佳答案,我也会尝试回答:
有没有一种方法可以在 Vue Cli 项目中在一个文件中创建多个组件,或者多个文件是创建组件的唯一方法?
人们总是为组件创建多个文件。
我希望这有帮助
推荐阅读
- java - Spring MVC @SessionAttribute缺少String []类型的会话属性错误
- cryptography - 如何将 HSM ECDSAPublicKey 转换为 java.security PublicKey
- regex - 如何编写正则表达式以在指定位置删除和添加字符?
- symfony - 在为现有数据库创建实体和存储库后生成初始迁移
- sql - 如何在 SQL 中计算从星期六而不是星期日开始的周数
- verilog - 总是阻塞verilog中的阻塞分配?
- mapbox - 如何使用 csv2geojson 数据添加标记而不是圆圈
- python - 如何在没有 IronPython 的情况下将 C#(winforms 应用程序)、当前文本框文本传递给 Python 变量
- spring-data-jpa - QueryDSL 表达式正在抛出 *java.lang.UnsupportedOperationException: null* 异常
- c++ - 如何预编译不以 .h 结尾的 C++ 头文件