1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LaravelでJavaScriptに変数を渡す方法

Posted at

方法はいくつかあるけど、たぶん『グローバル定義する』方法が一番良いと思う。(ファイルも分離できるから)

bladeファイルで下記のように記述。

<script>
window.laravel = {};
window.laravel.val1 = val1;
</script>

続いて、jsファイルで下記のように使える。

console.log(Laravel.val1);
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?