1
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.

vue3 vue.blade から 子 vueにデータを送る

Posted at

vue.blade.php のヘッダに 検索ボタンを付ける。
等という事案で使える。

親の変数を子要素でwatchして、子要素の処理をする。
といった流れ。

vue.blade.php

.js
<div @click="$root.searchFormVisible = true">検索ボタン</div>

app.js

色々略

    data () {
        return {
            searchBtnVisible:false,
            searchFormVisible:false,
        }
    },

これを子要素で察知したい。

UserShow.vue

watch: {
    //移動する度に動作させる
    //親メソッドの変更を察知する
    '$root.searchFormVisible'(data) {
        console.log(data);
    },
},

これで

  1. vue.blade.php のボタンを押せば
  2. app.js の searchFormVisible が発火
  3. UserShow.vueで取得できるので、フォームを表示などの処理が可能
1
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
1
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?