sourcetip

Vuex에서 v-select의 기본값을 두 스토어에서 어떻게 선택합니까?

fileupload 2023. 7. 7. 21:01
반응형

Vuex에서 v-select의 기본값을 두 스토어에서 어떻게 선택합니까?

Vuex 스토어에서 채우는 v-select가 있습니다.v-select에서 계산된 속성(고객)에서 가져온 다른 개체의 속성 ID와 일치하는 값을 선택해야 하지만 이 값을 사용할 수 없습니다.

상태를 변경하고 싶지 않습니다. 고객 객체의 priceListId ID에 따라 일치하는 드롭다운 값을 표시하고 싶습니다.

V-선택:

 <v-select :items="priceLists"
                      item-text="name"
                      item-value="id"
                      label="pricelist"
                      v-model="select"
                      select
                      return-object></v-select>

모델 코드:

export default {
  data: () => ({
    select: null
    }),
    computed: {
    priceLists () {
      return this.$store.state.pricelists.pricelists
    },
    customer () {
     return this.$store.state.customers.customers.find(customer => 
      customer.id === Number(this.customer.id))
 }
}

아이디어 있어요?

감시자 사용customer자동 설정select(가격 리스트의 v-model)<v-select>)에 의해 원하는 가격 리스트로.customer.priceListId:

watch: {
  customer: {
    immediate: true,
    handler(value) {
      this.select = value.priceListId;
    }
  }
}

데모

언급URL : https://stackoverflow.com/questions/53554011/how-do-you-select-a-default-value-in-v-select-from-vuex-from-two-stores

반응형