就是代码写的不规范
报错写法
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)
} )
文章讨论了在Vue应用中遇到的代码规范问题,具体是import导入和props定义不正确导致的错误。通过展示两种写法,一种产生错误,另一种是正确的,强调了在定义组件属性时正确使用defineProps和withDefaults以及提供默认值的重要性。修复后的代码确保了props的正确类型定义和初始化。
1679

被折叠的 条评论
为什么被折叠?



