【发布时间】:2019-10-07 14:07:12
【问题描述】:
我有一个主要的 App.vue 组件。在那里,我有以下代码:
export default {
data() {
return {
testVariable:false
}
},
}
</script>
<template>
<VApp :dark="testVariable:false"
<div id="app">
<RouterView :key="$route.fullPath" />
</div>
</VApp>
</template>
然后在其中一个组件中,我有以下代码:
data() {
return {
testVariable: this.$root.$children[0].testVariable,
}
},
methods: {
darkModeToggle(e) {
this.$root.$children[0].testVariable = e
},
},
问题 1) this.$root 和 this.$root.children 是什么意思?是this.$root 总是 App.vue 组件(因为 App.vue 是所有组件的父级)。 this.$root.children 是这个 App.vue 组件的子组件,这意味着所有其他组件都将在 this.$root.children 数组中?
问题2)这条线是什么意思?<RouterView :key="$route.fullPath" />。我的意思是我们为什么要通过:key="$route.fullPath"?
【问题讨论】:
标签: vue.js vuejs2 vue-component vue-router