我们目前正在从样板VUE 2转换为Composition API,并且我正在努力理解如何重写我们当前的computed以支持Composition API:
setup() {
const store = useStore();
// 问题:我如何将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: "姓氏",
},
...
...
];
},
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
不确定问题具体是什么,但我认为在计算属性中使用
store.getters应该可以解决:const infoFields = computed(() => { return [ { value: store.getters["contacts/getContact"].customer.firstName, label: "名字", }, { value: store.getters["contacts/getContact"].customer.lastName, label: "姓氏", } ] })