这个错误的原因是 withDefaults 函数的第二个参数中的 menuShow 属性类型与 Props 接口中的不匹配。可以将 withDefaults 函数的第二个参数中的 menuShow 属性类型改为与 Props 接口中的一致,如下所示:

const props = withDefaults(defineProps<Props>(), {
  clickType: '1',
  menuShow: {
    isShow: false,
    menuLeft: 0,
    menuTop: 0,
  } as Props['menuShow'], // 将 menuShow 属性类型改为与 Props 接口中的一致
});

或者可以使用 Partial 类型将 Props 接口中的 menuShow 属性变为可选属性,如下所示:

export interface Props {
  clickType: string,
   menuShow?: { // 将 menuShow 属性变为可选属性
    isShow: boolean,
    menuLeft: number,
    menuTop: number,
  }
}

const props = withDefaults(defineProps<Props>(), {
  clickType: '1',
  menuShow: {
    isShow: false,
    menuLeft: 0,
    menuTop: 0,
  }
});
``
export interface Props clickType string menuShow isShow boolean menuLeft number menuTop number const props = withDefaultsdefinePropsProps clickType 1 menuShow isShow false men

原文地址: https://www.cveoy.top/t/topic/eO7r 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录