# app.vue<template><divid="app"><p></p> </div></template><script>export default { data: function () { return { message: "Hello Vue!" } }}</script><stylescoped>p{font-size:2em;text-align:center;}</style># hello_vue.jsimport Vue from 'vue'import App from './app.vue'document.addEventListener('DOMContentLoaded', () => { document.body.appendChild(document.createElement('hello')) const app = new Vue(App).$mount('hello')console.log(app)})
建立 controller
1
bundleexecrailsgcontrollerpagesindex
更改 page index 內容 & router
1234567
# app/views/pages/index.html.erb<%= javascript_pack_tag 'hello_vue' %>s<%=stylesheet_pack_tag'application'%># router# root to: 'pages#index'root'pages#index'
啟動
啟動後,Webpacker 會自動 Compiling
若是有修改 vue 裡面的內容,頁面重新整理會在自動 Compiling
123456789
railssStartedGET"/"for127.0.0.1at2017-09-1711:58:29+0800ProcessingbyPagesController#index as HTMLRenderingpages/index.html.erbwithinlayouts/application[Webpacker]Compiling…[Webpacker]Compiledallpacksin/Users/leon/Code/practice/rails5/myapp/public/packsRenderedpages/index.html.erbwithinlayouts/application(4828.5ms)Completed200OKin6547ms(Views:6249.7ms)
也可以手動啟動 Webpack Dev Servers
這樣修改 vue 的內容,只要檔案 save 就會自動 Compiling,不需要面重新整理 (vue-hot-reload)