router-view
の変数の値を、異なるroutre-view
の変数を同期して変更したいと思います。ヘッダーに変数isFoo
を変更してサイドバーにキャッチすると、次のようなコードが書き込まれましたが失敗します。vue.js内のルータ間で変数を同期
App.vue:
<template>
<v-app id="app">
<router-view name="sidebar"></router-view>
<router-view name="header"></router-view>
<router-view name="main"></router-view>
<router-view name="footer"></router-view>
</v-app>
</template>
<script>
export default {
name: 'app',
isFoo: false
}
</script>
とSidebar.vue:
<template>
<div id="sidebar" :isOpen="isFoo"></div>
</template>
<script>
export default {
name: 'sidebar',
data() {
return {isFoo: this.$parent.$options.isFoo}
}
}
</script>
Header.vue:
<template>
<button v-on:click="foo()">Button</button>
</template>
<script>
export default {
name: 'header',
methods: {
foo:() => {
this.$parent.$options.isFoo = !this.$parent.$options.isFoo
}
}
}
</script>