0
0

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 から vue.jsへの値の受け渡し

Last updated at Posted at 2021-06-24

vue.jsの勉強を始めて二週間くらいです。今までやったことといえばvueのチュートリアルくらい
そんな僕がvueをとりあえず実践で使ってみようとlaravel bladeの中で使ってみたら思いのほか躓いたという話です。

やりたいこと

laravel.blade.php
<div id="test">
   @foreach( $informations as $information )
     <example-vue information_id="{{$information['id']}}"><example-vue>
   @endforeach
</div>

こんな感じでbladeの中でforeachで取り出した値をなんとかしてvueで使いたいなあ…と考えていました。
が、やり方が分からない。
これで一夜「laravel vue 値 受け渡し」みたいな単語で何度も検索していました。

全然簡単だった件

なんとかできるようになりました
が、終わってみると全然簡単でした。

propsなるものがあるそうで

vue.js
<script>
Vue.component('example-vue',{
  props: ['information_id'],
  template: '<p>@{{information_id}}</p>'
})

new Vue({ el: '#test' })
</script>

こんな感じでpropsでカスタムプロパティーにセットした値を受け取れます。

なんだ!めっちゃ簡単じゃんwww
てかチュートリアルにもあったはずなのになんで忘れてしまうん・・・

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?