LoginSignup
2
1

More than 3 years have passed since last update.

[Rails]Vue インスタンス内で js ファイルを読み込みたい

Last updated at Posted at 2019-06-15

Webpackeryarnslimを利用。
普通にやるとこんな感じでエラーがでる。

Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed.

vue-script2を使うと簡単にできる。

  • vue-script2をインストール
yarn add vue-script2
  • javascript/packs下にjsファイルを置く
javascript/packs/hello.js
console.log("hello")
  • <script2>タグを使って呼び出し
layout/application.html.slim
- path = asset_pack_path 'hello.js'
script2 src="#{path}"
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1