We are currently converting from boilerplate VUE 2 to the Composition API, and I'm struggling to understand how to rewrite our current computed to support the Composition API:
setup() { const store = useStore<StoreState>(); // 问题:我如何将infoFields实现到setup中? // const contactSingle = computed(() => store.state.contacts.contactSingle); return { contactSingle }; }, computed: { ...mapGetters("contacts", ["getContact"]), infoFields(): any { return [ { value: (this as any).getContact.customer.firstName, label: "名字", }, { value: (this as any).getContact.customer.lastName, label: "姓氏", }, ... ... ]; }, <v-row> <v-col class="pt-0" v-for="(item, i) in infoFields" :key="i + '-field'" cols="12" xs="12" sm="6" md="6" lg="4"> <BaseSheetField :value="item.value" :label="item.label" /> </v-col> </v-row>
Not sure what the problem is exactly, but I think using
store.getters
in the computed property should solve it: