vue3 父传子类型校验写法

写法一:

import type { myOrderItem } from '@/API/pages_mine/myOrder/types';

const props = defineProps({
  item: {
    type: Object as PropType<myOrderItem>,
    default: () => ({})
  }
});

写法二

import type { ChartData } from '@/API/statistics/types';

const props = defineProps({
  data: {
    type: Array<ChartData>,
    default: () => ([])
  }
})

写法三:

interface Props {
  columns: number; // 几列
  align: string; // 对齐方式
  form: any; // 数据模板
  detail: any; // 数据
  labelWidth?: number; // labelwidth
}
const prop = withDefaults(defineProps<Props>(), {
  columns: 1,
  align: 'right',
  form: [] as any,
  detail: {} as any,
  labelWidth: 0,
});
  • 推荐写法三
posted @ 2024-08-15 17:47  DL·Coder  阅读(5)  评论(0编辑  收藏  举报