|
1 | 1 | # VueOnRails
|
2 | 2 |
|
3 |
| -Easy and simple way to use Vue.js with Ruby on Rails and Turbolinks 5. |
| 3 | +Simple and fast way to use Vue.js with Ruby on Rails and Turbolinks 5. |
4 | 4 |
|
5 |
| -This gem is intended to sprinkle your Rails app with Vue components. Really lightweight script (1.3KB minified) that mount and destroy Vue components on demand. It's works nicely with Turbolinks rendering and caching system. |
| 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. |
| 6 | + |
| 7 | +It works nicely with: |
| 8 | +- Turbolinks rendering and caching system |
| 9 | +- Javascript loaded asynchronously with defer or async script attribute |
| 10 | + |
| 11 | +It's fully Google PageSpeed friendly since you can use it with defer or async, no need for render-blocking JavaScript :) |
6 | 12 |
|
7 | 13 | If you are building a pure SPA app with Vue and Rails without Turbolinks, you will be better off looking into:
|
8 | 14 | https://github.com/adambutler/vuejs-rails
|
@@ -39,19 +45,23 @@ Require vue_on_rails in application.js
|
39 | 45 | Mount and destroy Vue components:
|
40 | 46 | ```
|
41 | 47 | # Mount Vue components
|
42 |
| -document.addEventListener 'turbolinks:load', -> |
43 |
| - VueOnRails.mountComponents() |
| 48 | +document.addEventListener('turbolinks:load', function() { |
| 49 | + VueOnRails.mountComponents(); |
| 50 | +}); |
44 | 51 |
|
45 | 52 | # Destroy Vue components
|
46 |
| -document.addEventListener 'turbolinks:before-render', -> |
47 |
| - VueOnRails.destroyComponents() |
| 53 | +document.addEventListener('turbolinks:before-render', function() { |
| 54 | + VueOnRails.destroyComponents(); |
| 55 | +}); |
48 | 56 | ```
|
| 57 | +VueOnRails.mountComponents() will scan the page and mount components using data-vue-component and data-vue-props. |
49 | 58 |
|
50 |
| -Example Vue component in my_component.coffee |
| 59 | +Example Vue component in my_component.js |
51 | 60 | ```
|
52 |
| -@MyComponent = |
53 |
| - props: ['myProp'] |
| 61 | +MyComponent = { |
| 62 | + props: ['myProp'], |
54 | 63 | template: '<div>A custom component with {{myProp}}</div>'
|
| 64 | +}; |
55 | 65 | ```
|
56 | 66 |
|
57 | 67 | Add component in view.html.erb
|
@@ -85,7 +95,7 @@ Props are automatically hyphen-delimited to follow vuejs and HTML5 standard.
|
85 | 95 |
|
86 | 96 | ### Dynamic props
|
87 | 97 | ```
|
88 |
| -<%= vue_component 'MessageComponent', ':my_message': 'hello world' %> |
| 98 | +<%= vue_component 'MessageComponent', ':my_object': { title: 'Test', subtitle: 'Sweet!' } %> |
89 | 99 | ```
|
90 | 100 |
|
91 | 101 | ## Contributing
|
|
0 commit comments