0
我想通過同步更改不同routre-view
中的其他變量來更改router-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>