programing

구성 요소 내부의 계산된 속성에 프로펠러 값 전달

prostudy 2022. 6. 28. 22:28
반응형

구성 요소 내부의 계산된 속성에 프로펠러 값 전달

컴포넌트 내부의 계산된 속성 함수 내에서 프로펠러 값을 사용할 수 있습니까?그렇다면 이 소품으로 어떻게 반품할 수 있을까요?

회전목마.표시하다

props: [
  'source',
],
computed: {
   items () {
     return this.$store.state.(prop value source here).list
   }
}

store/categorya.category(categoryb 및 categoryc와 동일)

import categorya from '(...)'
export const state = () => ({
  list: categorya
})

갱신하다

Index.vue

carousel(source="categorya")
carousel(source="categoryb")
carousel(source="categoryc")

질문이 좀 애매해요.source가 Vuex 모듈 이름을 지정하는 경우 괄호 표기법을 사용할 수 있습니다.

computed: {
  items () {
    return this.$store.state[this.source].list
  }
}

편집 후

아직 불분명하지만 모듈이 없는지,listroot 스테이트의 속성입니다.그러면 다음 명령을 사용할 수 있습니다.

computed: {
  items () {
    return this.$store.state.list
  }
}

이 사실은list는 처음에 Import에 의해 정의됩니다.categorya차이가 전혀 없다.아직 유일한 주(州)이며 이름은list.

언급URL : https://stackoverflow.com/questions/60454105/pass-prop-value-to-computed-properties-inside-a-component

반응형