当前位置: 代码网 > it编程>编程语言>Javascript > Props传参v-for后TS报错对象类型是unknow的解决方案

Props传参v-for后TS报错对象类型是unknow的解决方案

2024年05月18日 Javascript 我要评论
此时的groups是props传过来的参数,vue3在模板里面使用props也需要加props。import { defineprops} from 'vue'const props = define

此时的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报错内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com