如何简化vue3代码?

import { computed } from 'vue';
export interface Props {
  data: {
    div: {... }[];
    progress: {...};
  };
}
const { data } = defineProps<Props>();
const div = computed(() => data.div);
const progress = computed(() => data.progress);

我希望直接使用div,progress,它们需要保持响应式,如何简化呢?

...

阅读 555
2 个回答
✓ 已被采纳
const { div, progress } = toRefs(data);
import { computed } from 'vue';

export interface Props {
  data: {
    div: {...}[];
    progress: {...};
  };
}

const { data } = defineProps<Props>();

const { div, progress } = computed(() => ({
  div: data.div,
  progress: data.progress
}));
推荐问题
宣传栏