gpt4 book ai didi

ruby-on-rails - Rails + webpacker + vue : "You are using the runtime-only build of Vue where the template compiler is not available."

转载 作者:搜寻专家 更新时间:2023-10-30 22:09:15 26 4
gpt4 key购买 nike

我创建了一个新的 Rails 5.2 应用程序并安装了 vue:

bundle exec rails webpacker:install:vue

在创建一个简单的端点 Home#landing 并添加 <%= javascript_pack_tag 'hello_vue' %> 之后对于默认布局,示例应用程序按预期工作。

我做了一些改变:

1) 将 hello_vue.js 修改为,

import Vue from 'vue'

document.addEventListener('DOMContentLoaded', () => {
const app = new Vue({
el: '#vueapp',
data: {
message: "Hello Vue!"
}
})
})

2) 创建并清空 <div id="vueapp"> {{ message }} </div>在我唯一的视野中。

3) 从 app/javascripts 中删除了 app.vue。

据我所知,这也应该有效(这就是我们使用与链轮一起运行的 vue-rails gem 的方式)。现在失败了:

[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 N​​PM 包的默认导出仅为运行时。

由于您需要模板编译器,因此需要将 Vue 导入更改为以下内容,其中包括运行时和模板编译器:

import Vue from 'vue/dist/vue.esm.js';

更多详情:此处https://v2.vuejs.org/v2/guide/installation.html#Explanation-of-Different-Builds

关于ruby-on-rails - Rails + webpacker + vue : "You are using the runtime-only build of Vue where the template compiler is not available.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50473630/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com