All Projects → benoitongit → vue-on-rails

benoitongit / vue-on-rails

Licence: MIT license
Easy way to mount/destroy Vue.js components with Ruby on Rails and Turbolinks 5

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to vue-on-rails

vue-scroll-snap
A super simple Vue component that allows fullscreen and horizontal scroll snapping.
Stars: ✭ 25 (+47.06%)
Mutual labels:  vue-components
vstx-data-table
A data table component for the Vue Stacks Ecosystem
Stars: ✭ 34 (+100%)
Mutual labels:  vue-components
okeedesign-mobile-vue
High Performance, Flexiable Configuration, Various Components
Stars: ✭ 139 (+717.65%)
Mutual labels:  vue-components
unique-ui
一个用于Vue2.x的移动端组件库
Stars: ✭ 43 (+152.94%)
Mutual labels:  vue-components
react-cheat-sheet
📚 The perfect React Cheat Sheet for daily use with a lot of Javascript / JSX snippets !
Stars: ✭ 59 (+247.06%)
Mutual labels:  props
vue-flexmonster
Vue Module for Flexmonster Pivot Table & Charts
Stars: ✭ 16 (-5.88%)
Mutual labels:  vue-components
chusho
A library of bare & accessible components and tools for Vue.js 3
Stars: ✭ 47 (+176.47%)
Mutual labels:  vue-components
vue-cli-plugin-quasar
Quasar Framework Vue CLI plugin
Stars: ✭ 66 (+288.24%)
Mutual labels:  vue-components
vue-skeleton-loader
A simple and easily customizable skeleton loader plugin for you Vue application.
Stars: ✭ 74 (+335.29%)
Mutual labels:  vue-components
Different-UI
✨ A Vue.js 3 UI Library — a Toy
Stars: ✭ 62 (+264.71%)
Mutual labels:  vue-components
shadow
Shadow dom support for Vue
Stars: ✭ 46 (+170.59%)
Mutual labels:  vue-components
jss-material-ui
A enhanced styling engine for material-ui
Stars: ✭ 15 (-11.76%)
Mutual labels:  props
ignore
🔥修炼内功,无招胜有招。 ---个人博客
Stars: ✭ 27 (+58.82%)
Mutual labels:  vue-components
vue-mobiledoc-editor
A lightweight and customizable editor that allows you to embed rich content using Vuejs components.
Stars: ✭ 73 (+329.41%)
Mutual labels:  vue-components
vue-cirrus
Vue components for the Cirrus CSS framework.
Stars: ✭ 43 (+152.94%)
Mutual labels:  vue-components
void-ui
A UI toolkit for Vue.js.
Stars: ✭ 20 (+17.65%)
Mutual labels:  vue-components
vue-data-loading
Another component for infinite scroll and pull down/up to load data.
Stars: ✭ 63 (+270.59%)
Mutual labels:  vue-components
rails-vue-components-example
Ruby on Rails with vue.js single-file components example.
Stars: ✭ 20 (+17.65%)
Mutual labels:  vue-components
v-owl-carousel
🦉 VueJS wrapper for Owl Carousel
Stars: ✭ 46 (+170.59%)
Mutual labels:  vue-components
vue-clock-simple
Repo for the article How To Publish Your Vue.js Component On NPM
Stars: ✭ 88 (+417.65%)
Mutual labels:  vue-components

VueOnRails

Simple and fast way to use Vue.js with Ruby on Rails and Turbolinks 5.

This gem is fantastic to sprinkle your web page with Vue components. Lightweight script (1KB minified) that mounts and destroys Vue components on demand.

It works nicely with:

  • Turbolinks rendering and caching system
  • Javascript loaded asynchronously with defer or async script attribute

It's fully Google PageSpeed friendly since you can use it with defer or async, no need for render-blocking JavaScript :)

If you are building a pure SPA app with Vue and Rails without Turbolinks, you will be better off looking into: https://github.com/adambutler/vuejs-rails

Requirements

Installation

Add this line to your application's Gemfile:

gem 'vue_on_rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install vue_on_rails

Usage

Require vue_on_rails in application.js

//= require vue_on_rails

Mount and destroy Vue components:

# Mount Vue components
document.addEventListener('turbolinks:load', function() {
  VueOnRails.mountComponents();
});

# Destroy Vue components
document.addEventListener('turbolinks:before-render', function() {
  VueOnRails.destroyComponents();
});

VueOnRails.mountComponents() will scan the page and mount components using data-vue-component and data-vue-props.

Example Vue component in my_component.js

MyComponent = {
  props: ['myProp'],
  template: '<div>A custom component with {{myProp}}</div>'
};

Add component in view.html.erb

<%= vue_component 'MyComponent', my_prop: 'awesome prop!' %>
<!-- This will output -->
<div data-vue-component="MyComponent" data-vue-props="{&quot;my-prop&quot;:&quot;awesome prop!&quot;}">
   <div>A custom component with awesome prop!</div>
</div>

View Helper

A view helper generate a div with component and props:

def vue_component(component_name, props = {}, html_options = {})

Example with html tag:

<%= vue_component 'UserComponent', { user_id: 1 }, { class: 'd-inline-block align-middle' } %>
<!-- Becomes: -->
<div data-vue-component="UserComponent" data-vue-props="{'user-id': 1}" class="d-inline-block align-middle">
...
</div>

Props

Kebab-case (hyphen-delimited)

Props are automatically hyphen-delimited to follow vuejs and HTML5 standard.

Dynamic props

<%= vue_component 'MessageComponent', ':my_object': { title: 'Test', subtitle: 'Sweet!' } %>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/benoitontgit/vue-on-rails.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].