programing

이게 뭘까?$root는 컴포넌트 내를 의미합니까?

prostudy 2022. 8. 24. 23:31
반응형

이게 뭘까?$root는 컴포넌트 내를 의미합니까?

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) 이 기능은 무엇입니까?$root와 이것.$root.children은 무슨 뜻입니까?this.$root항상 App.vue 컴포넌트(App.vue가 모든 컴포넌트의 상위 컴포넌트이기 때문입니다).this.$root.children이 App.vue 컴포넌트의 하위 컴포넌트(다른 컴포넌트는 모두 다음 컴포넌트)에 있습니다.this.$root.children어레이?

질문 2) 이 행은 무엇을 의미합니까?<RouterView :key="$route.fullPath" />내 말은, 왜 우리는 통과하지?:key="$route.fullPath"?

this.$root

이.$root.아이들.

이것은.$root always App.vue 컴포넌트?

  • 아니요.App.vue상위 컴포넌트가 있습니다.new Vue(...)기본적으로는, 그 때문에new Vue(...)실제의$root

이것은.$root.이 App.vue 컴포넌트의 자녀는 다른 모든 컴포넌트가 이 컴포넌트에 포함됨을 의미합니다.$root.children 어레이?

  • .childrenDIRECT 하위 구성 요소이지 하위 구성 요소가 아닙니다.이 경우,$root직계 자녀는 1명뿐입니다.즉,App.vue

이 행은 무엇을 의미합니까?-왜 :key="$route를 통과합니까?fullPath?

  • https://stackoverflow.com/a/52848095/5599288에 잘 설명되어 있습니다.

언급URL : https://stackoverflow.com/questions/56233887/what-does-this-root-means-in-a-component

반응형