- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将 VueJS 添加到我现有的 Rails 应用程序中。
所以我将这些 gems 添加到我的 Gemfile 中:
gem 'webpacker'
gem 'foreman'
然后我跑了bundle
, rails webpacker:install
, rails webpacker:install:vue
, yarn install
.
它创建了一个 javascript
文件夹:一个app.vue
文件和一个 packs
带有 hello_vue.js
的文件夹文件和 application.js
文件。
应用程序/javascript/app.vue
<template>
<div id="app">
<p>{{ message }}</p>
</div>
</template>
<script>
export default {
data: function () {
return {
message: "Hello Vue!"
}
}
}
</script>
<style scoped>
p {
font-size: 2em;
text-align: center;
}
</style>
应用程序/javascript/packs/application.js
/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
console.log('Hello World from Webpacker')
应用程序/javascript/packs/hello_vue.js
/* eslint no-console: 0 */
// Run this example by adding <%= javascript_pack_tag 'hello_vue' %> (and
// <%= stylesheet_pack_tag 'hello_vue' %> if you have styles in your component)
// to the head of your layout file,
// like app/views/layouts/application.html.erb.
// All it does is render <div>Hello Vue</div> at the bottom of the page.
import Vue from 'vue'
import App from '../app.vue'
document.addEventListener('DOMContentLoaded', () => {
document.body.appendChild(document.createElement('hello'))
const app = new Vue({
render: h => h(App)
}).$mount('hello')
console.log(app)
})
// The above code uses Vue without the compiler, which means you cannot
// use Vue to target elements in your existing html templates. You would
// need to always use single file components.
// To be able to target elements in your existing html/erb templates,
// comment out the above code and uncomment the below
// Add <%= javascript_pack_tag 'hello_vue' %> to your layout
// Then add this markup to your html template:
//
// <div id='hello'>
// {{message}}
// <app></app>
// </div>
// import Vue from 'vue/dist/vue.esm'
// import App from '../app.vue'
//
// document.addEventListener('DOMContentLoaded', () => {
// const app = new Vue({
// el: '#hello',
// data: {
// message: "Can you say hello?"
// },
// components: { App }
// })
// })
//
//
//
// If the using turbolinks, install 'vue-turbolinks':
//
// yarn add 'vue-turbolinks'
//
// Then uncomment the code block below:
//
// import TurbolinksAdapter from 'vue-turbolinks';
// import Vue from 'vue/dist/vue.esm'
// import App from '../app.vue'
//
// Vue.use(TurbolinksAdapter)
//
// document.addEventListener('turbolinks:load', () => {
// const app = new Vue({
// el: '#hello',
// data: {
// message: "Can you say hello?"
// },
// components: { App }
// })
// })
我实际上想开始使用 VueJS 来构建我的 FAQ 页面,所以这是我的 faq.html.erb 文件(只是为了看看 helloworld 示例是否有效):
<%= javascript_pack_tag 'hello_vue' %>
<div id="hello container">
<h1>{{message}}</h1>
<app />
</div>;
然后我运行 foreman start
.
我得到以下错误:
ERROR in ./app/javascript/app.vue
18:26:08 frontend.1 | Module parse failed: Unexpected token (1:0)
18:26:08 frontend.1 | You may need an appropriate loader to handle this file type.
18:26:08 frontend.1 | | <template>
18:26:08 frontend.1 | | <div id="app">
18:26:08 frontend.1 | | <p>{{ message }}</p>
18:26:08 frontend.1 | @ ./app/javascript/packs/hello_vue.js 9:0-29
18:26:08 frontend.1 | @ multi (webpack)-dev-server/client?http://localhost:3035 ./app/javascript/packs/hello_vue.js
如何在 Rails 上正确使用 Vue JS?
最佳答案
我遇到了同样的问题。但是更新 gem 对我没有帮助。
在config/webpack/development中我改成了
const environment = require('./environment')
const { VueLoaderPlugin } = require('vue-loader')
var newPlugin = environment.toWebpackConfig();
newPlugin.plugins.push(new VueLoaderPlugin());
module.exports = newPlugin;
在 config/webpack/enviroment.js 中
const { environment } = require('@rails/webpacker')
const vue = require('./loaders/vue')
environment.loaders.append('vue', vue)
environment.loaders.append('babel', {
test: /\.js$/,
loader: 'babel-loader'
})
module.exports = environment
关于javascript - Vue JS 2 on Rails 5.1 'You may need an appropriate loader to handle this file type.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47981803/
我有一个数据集,其列如下所示: Consumer ID | Product ID | Time Period | Product Score 1 | 1 | 1
举个例子。有一个我想使用的对象,称它为 Doodad。 Doodad 元素对浏览器事件的处理很差。 Doodad 的典型实例是 Doodad someDoodad = new Doodad();。显然
我正在构建一个基于 Java 的 Web 应用程序(主要是使用 Tomcat 部署的 JSP)。用户数量永远不会超过 30 人。它是一个工作日志,因此用户将不断更新/访问数据库 (SQL Server
我有一个名为 account 的抽象类,如下所示 - abstract class Account { private int number; private String owner
我目前忙于响应式字体大小。我很清楚 vh、vw、vmin 等单位的含义。 但我无法与他们一起完成令人信服的事情。它们要么在大屏幕上变大,要么在小屏幕上变小。反之亦然。 是否有任何适用于哪些值的一般规则
我定义了一个名为“FilterCriteria”的类,它有一堆与之关联的函数 .m 文件(getAMask、getBMask 等)。当我创建 FilterCriteria 对象并使用它调用函数时,我没
我正在尝试保存具有“类似论坛”结构的数据: 这是简化的数据模型: +---------------+ | Forum | | | | Name
我正在寻找一种在 Java 中验证数据库模式是否正常、默认值是否正常、触发器是否正常的方法。我找到了很多框架来测试数据库交互,但找不到可以让我测试表和模式的东西。有什么框架吗?如果数据库尚未同步,它将
题目地址:https://leetcode.com/problems/friends-of-appropriate-ages/description/ 题目描述: Some people will
我有以下代码: fn main() { let get = |v: &u32| -> &u32 { v }; let x : u32 = 0; let
在下面的代码中选择适当的 Web 服务方法的逻辑是什么? 客户: HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic
背景:我正在创建一个返回切片引用的迭代器 &[T] ,但数据向量需要保持不变。迭代器不能修改原始数据,但修改后必须重复返回同一个切片指针。我考虑过让我的迭代器拥有一个 Vec ,但我想避免这种情况(而
我有一个接受枚举引用的函数,我需要通过匹配枚举并读取其内容来解析它。枚举的一种变体(不在下面的简化的最小工作示例中)可能包含枚举本身的类型作为值,因此我可能需要递归调用相同的函数来解析它的值。 我想编
DROP TABLE temp; CREATE TABLE `temp` ( `CallID` bigint(8) unsigned NOT NULL,
无法编译以下内容。这里有什么问题吗? class B; class A { public: void DoSomething() { ... B* my
我在 Wheel of Luck Game 中需要其他帮助。我需要在 6 个 div 中选择 3 个 DIV。但是如果我选择如下图所示的 div 会发生什么,它将分别选择 6 No DIV 而不是 5
我想在不使用 STL 的情况下创建一个数组链表。但是,我在将数组传递到我的链接列表时遇到困难... 编译时出现上面列出的错误。我需要如何将数组传递给链表?谢谢! (有问题的代码有**标记,如果测试请去
我正在使用 Entity Framework 作为我的 ORM 对两个 SQL 函数进行连接。执行查询时,我收到此错误消息: The query attempted to call 'Outer Ap
我所做的只是导入一个 npm 包 import TimePicker from 'simple-timepicker-react' render () { return (
我有一个使用 bower 和 webpack 的 React 项目。 我正在尝试使用这个模块 https://github.com/jrowny/react-absolute-grid . 我用 np
我是一名优秀的程序员,十分优秀!