【问题标题】:Error with Vue-CLI Component : You are using the runtime-only build of Vue where the template compiler is not availableVue-CLI 组件错误:您正在使用仅运行时构建的 Vue,其中模板编译器不可用
【发布时间】:2019-02-14 08:55:37
【问题描述】:

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.js vuejs2 vue-component vue-loader


    【解决方案1】:

    我的项目也有同样的错误。我通过以下方式解决了它:

    1. 创建一个新文件:vue.config.js
    2. 并添加:

      module.exports = {
        runtimeCompiler: true
      }
      

    关于你的问题,我会尽量回答,即使我可能没有给出最好的答案:

    有没有一种方法可以在 Vue Cli 项目中创建多个组件 在一个文件或多个文件中是创建 组件?

    人们总是为组件创建多个文件。

    希望对你有帮助

    【讨论】:

    • 在哪里创建文件vue.config.js ?那怎么用呢?
    • 在根目录@IstiaqueAhmed
    猜你喜欢
    • 2021-08-29
    • 2018-11-01
    • 2018-04-30
    • 2018-08-15
    • 2022-12-16
    • 2017-09-22
    • 2017-10-09
    • 2017-11-24
    • 2020-06-16
    相关资源
    最近更新 更多