Props传参v-for后TS报错对象类型是unknow的解决方案,
3672Js.Com2024-04-11 02:27 来源:未知 阅读:706 关注度4
Props传参v-for后TS报错对象类型是unknow的解决方案,
此时的groups是props传过来的参数,vue3在模板里面使用props也需要加props。
import { defineProps} from 'vue' const props = defineProps({ groups: { type: Array , default: null } })
1.此时需要定义一个ts文件对group进行定义类型即可
/** * type.ts */ export type IGroup = { type不能忘记写 name: string color: string count: number status: string icon: string headers: [{ name: string; key: string; format: any }] data: any[] 这里应该还需要细加定义,但是我偷懒了 operators: [ { name: string icon: string handle: any } ] }
2.在组件中引入该类型
import { defineProps, type PropType } from 'vue' import type { IGroup } from '@/api/types' PS:这里引入要写前面type const props = defineProps({ groups: { type: Array as unknown as PropType<[IGroup]>, 需要先定义unknown default: null } })
到此这篇关于Props传参v-for后TS报错对象类型是unknow的文章就介绍到这了,更多相关Props传参v-for报错内容请搜索3672js教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持3672js教程!
您可能感兴趣的文章:- Vue3中props传参方式详解
- vue3 setup语法糖之组件传参(defineProps、defineEmits、defineExpose)示例详解
- Vue路由传参props解耦的三种方式小结
- Vue中data传递函数、props接收函数及slot传参的使用及说明
- Vue路由传参及props解耦深入分析
- vuejs路由的传参及路由props配置详解
- Vue路由组件通过props配置传参的实现
本站文章为3672js教程网友分享投稿,版权归原作者,欢迎任何形式的转载,但请务必注明出处。同时文章内容如有侵犯了您的权益,请联系我们处理。
评论已被关闭