Vue.js 在组件中,$root意味着什么?
我有一个主App.vue组件。在这里,我有以下代码:Vue.js 在组件中,$root意味着什么?,vue.js,vuejs2,vue-component,vue-router,Vue.js,Vuejs2,Vue Component,Vue Router,我有一个主App.vue组件。在这里,我有以下代码: export default { data() { return { testVariable:false } }, } </script> <template> <VApp :dark="testVariable:false" <div id="app"> <RouterView :key="$route.fullPath" /&g
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)这个$root和这个$root.children是什么意思?是this.$root
始终是App.vue组件(因为App.vue是所有组件的父级)。this.$root.children
是否是此App.vue组件的子组件,这意味着所有其他组件都将位于this.$root.children
数组中
问题2)这一行是什么意思?
。我的意思是为什么我们要传递:key=“$route.fullPath”?
这个。$root
- 当前组件树的根Vue实例李>
- 当前实例的直接子组件李>
- 没有。
有一个父组件,它是main.js中的App.vue
。因此,新vue(…)
就是实际的新的Vue(…)
$root
是直接的子组件,而不是子组件。在这种情况下,.children
只有一个直接子级,即$root
App.vue
- 这在书中解释得很好
- 当前组件树的根Vue实例李>
- 当前实例的直接子组件李>
- 没有。
有一个父组件,它是main.js中的App.vue
。因此,新vue(…)
就是实际的新的Vue(…)
$root
是直接的子组件,而不是子组件。在这种情况下,.children
只有一个直接子级,即$root
App.vue
- 这在书中解释得很好