vue3中props中数组报错 ‘item‘ is of type ‘unknown‘

在vue3项目中,props父组件的list,在html中遍历的时候会报错 'item' is of type 'unknown',是以为没有显示的表示出list中item的类型,可以使用一下方式:

interface Task {
  key:number,
  title:string,
}

const props = defineProps({  
        historyList: {
            type: Array<Task>, // 或者Task[]
            required: true
        }
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue,可以使用props选项来传递数组。有两种常见的方式来传递数组作为props。 第一种方式是使用数组形式的props声明。在子组件,可以通过在props选项使用数组来声明需要从父组件接收的数据。例如,子组件的代码可以如下所示: ```html <template> <div> <p>我是子组件,接收来自父组件的信息:{{message}}</p> </div> </template> <script> export default { name: "child", props: \['message'\] } </script> <style scoped> </style> ``` 在父组件,可以通过在子组件的标签上使用v-bind指令来传递数组作为props。例如: ```html <child :message="\['Hello', 'World'\]"></child> ``` 这样,子组件就可以接收到父组件传递的数组。 第二种方式是使用对象形式的props声明。在子组件,可以通过在props选项使用对象来声明需要从父组件接收的数据。例如,子组件的代码可以如下所示: ```html <template> <div> <p>我是子组件,接收来自父组件的信息:{{message}}</p> </div> </template> <script> export default { name: "child", props: { message: Array } } </script> <style scoped> </style> ``` 在父组件,可以通过在子组件的标签上使用v-bind指令来传递数组作为props。例如: ```html <child :message="\['Hello', 'World'\]"></child> ``` 这样,子组件就可以接收到父组件传递的数组。 总结起来,Vue可以通过数组形式的props声明或对象形式的props声明来传递数组作为props。 #### 引用[.reference_title] - *1* [Vue 组件之使用props传递数据](https://blog.csdn.net/qingyulove/article/details/81613319)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Vue 组件传参的几种方式](https://blog.csdn.net/weixin_45959525/article/details/104729867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值