Invalid prop: type check failed for prop "data". Expected Array, got Object
时间: 2023-10-18 15:29:48 浏览: 181
引用中的代码显示,问题出现在将对象赋值给期望接收数组的属性上。具体来说,错误信息"Invalid prop: type check failed for prop "data". Expected Array, got Object"表明在props属性中,指定了一个期望接收数组类型的属性"data",但实际传入的却是一个对象。
解决这个问题的方法是,将对象转换为数组,确保props属性接收到的是一个数组类型的值。在代码中,可以使用Object.values()方法将对象的值转换为数组。
以下是一种解决方法:
```
data() {
return {
cinemaInfo: {},
halls: [],
url: ""
}
},
methods: {
getCinemaInfo() {
this.request.get("/cinema").then(res => {
if (res.code === '200') {
console.log(res);
this.cinemaInfo = Object.values(res.data)[0];
this.halls = Object.values(res.data)[0].hallTypeList.split(',');
this.url = Object.values(res.data)[0].picture;
console.log(this.cinemaInfo);
}
})
}
}
```
这样,通过将res.data的值转换为数组,将其赋给this.cinemaInfo属性,就能解决这个类型不匹配的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [vue常见错误:Invalid prop: type check failed for prop “data“. Expected Array, got Object](https://blog.csdn.net/qq_41485414/article/details/90263613)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [解决Vue报错解决Invalid prop: type check failed for prop “model“. Expected Object, got Array的问题](https://blog.csdn.net/weixin_51641169/article/details/126289389)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文