getApi('/v1/purchase_orders.json', {}).then(res => {
console.info(res)
if (res instanceof UTSJSONObject) {
this.purchaseOrderList = res['data'] as PurchaseOrderType[]
console.info(this.purchaseOrderList)
console.info(this.purchaseOrderList[0].id)
}
})
打印结果
[UTSJSONObject] {total: 4, code: 0, data: [ ... ], message: ""} at pages/purchase/list.uvue:40
08:36:30.657 [Array] [ {status_zh: "待办", inbound_at: "2024年05月27日", purchase_order_items: [ ... ], trade_no: "PO20240527103106963", created_at: "2024年05月27日", ...}, {status_zh: "待办", inbound_at: "2024年05月09日", purchase_order_items: [ ... ], trade_no: "PO20240509173756969", created_at: "2024年05月09日", ...}, {status_zh: "待办", inbound_at: "2024年05月21日", purchase_order_items: [], trade_no: "PO20240504160448456", created_at: "2024年05月04日", ...}, {status_zh: "入库", inbound_at: "2024年05月06日", purchase_order_items: [ ... ], trade_no: "PO20240504092139970", created_at: "2024年05月04日", ...} ] at pages/purchase/list.uvue:43
08:36:30.670 Possible Unhandled Promise Rejection: [java.lang.ClassCastException] {cause: null, message: "io.dcloud.uniapp.vue.UTSReactiveJSONObject cannot be cast to uni.UNI6877788.PurchaseOrderType"}
具体不清楚怎么解决
5 个回复
DCloud_heavensoft
不是v-for的问题。
我感觉你的purchaseOrderList 并没有变成有效类型,你可以打印purchaseOrderList[0].id 看看。
理论上应该是res那里直接用泛型转type,as应该是不行的
8***@qq.com (作者)
打印结果
具体不清楚怎么解决
沈工
this.purchaseOrderList = res['data'] as Array<PurchaseOrderType> 改 this.purchaseOrderList = res['data']
沈工
或者 :key="item.id" 改:key="index"
2024-06-20 08:48
8***@qq.com (作者)
已解决,先转字符串,再转类型
1***@qq.com
我的怎么报类型声明的错啊?Cannot infer a type for this parameter. Please specify it explicitly.
数据打印出来是