お世話になっております。
Rails + Vueの環境構築時に「コンストラクターがない」というエラーが出て解決できずにいます。ご助言いただけると幸いです。
前提事項
rails 6.1.5
vue 2.6.14
vuetify v2.6.4
エラー内容
Uncaught TypeError: ... is not a constructor
というエラーにより、VueのHello Vue!が表示されない。
ChromeDevelopperTool
1hello_vue.js:12 Uncaught TypeError: vue__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor 2 at HTMLDocument.<anonymous> (hello_vue.js:12:1)
app/javascript/packs/hello_vue.js
1/* eslint no-console: 0 */ 2// Run this example by adding <%= javascript_pack_tag 'hello_vue' %> (and 3// <%= stylesheet_pack_tag 'hello_vue' %> if you have styles in your component) 4// to the head of your layout file, 5// like app/views/layouts/application.html.erb. 6// All it does is render <div>Hello Vue</div> at the bottom of the page. 7 8import Vue from 'vue' 9import App from '../app.vue' 10 11document.addEventListener('DOMContentLoaded', () => { 12 const app = new Vue({ <=ここでエラー発生 13 render: h => h(App) 14 }).$mount() 15 document.body.appendChild(app.$el) 16 17 console.log(app) 18})
経緯
作りたてのRailsプロジェクトでのエラーです。
Rails new
$ rails _6.1.5_ new . -d mysql --skip-test --webpack=vue
データベース作成
$ rails db:create
コントローラー作成
rails g controller home index
ルーティングも完了し、homeビューの表示まで正常に動作しています。
参考:https://qiita.com/Ryoga_aoym/items/e1d91351389904240594
お忙しいところ申し訳ありませんが、ご助言いただけると幸いです。
回答1件
あなたの回答
tips
プレビュー