Vue Typescript 引入文件接口,就无法使用withDefaults

就是代码写的不规范

报错写法

	import {Setting} from '@element-plus/icons-vue'
	import { defineProps ,withDefaults } from 'vue'
	import {PiProject} from '@/types/Project'
	interface ProjectCardProps{
		project:PiProject
	}
	const props = defineProps<ProjectCardProps>();

	withDefaults(props,{
		project:{}
	} )

返回值得是一个函数

正确写法

	import {Setting} from '@element-plus/icons-vue'
	import { defineProps ,withDefaults } from 'vue'
	import {PiProject} from '@/types/Project'
	interface ProjectCardProps{
		project:PiProject
	}
	const props = defineProps<ProjectCardProps>();
	withDefaults(props,{
		project:():PiProject=>({

		} as PiProject)
	} )
posted @ 2023-04-22 22:11  皮豪  阅读(322)  评论(0编辑  收藏  举报