"TypeError: Cannot read properties of undefined (reading 'map')"
出现类似的情况,调用数组方法,报识别不到的错误,是因为你要更改的数组为空,所以是是别不到此方法。
选则商品是渲染已选择的商品
checkProductAttrDesc(){
if(this.specificationList.length){
return this.checkAllId.map((item,index)=>{
return this.specificationList[index].valueList.find(val=>val.id===item).value
}).join(',')
}else{
return ''
}
},
checkProductImsge(){
if(this.specificationList.length){
const checkAttrList= this.checkAllId.map((item,index)=>{
return this.specificationList[index].valueList.find(val=>val.id===item).pic_url
})
let picUrl=''
checkAttrList.forEach(item=>{
if(item) picUrl=item
})
return picUrl
}else{
return this.info.list_pic_url
}
},
先判断商品是否有多种规格,如果有当我们选择时,保留选择的商品对应的索引,之后在遍历索引,拿出来放入数组中,list[0],这种形式。遍历次商品中的类型中的索引和我们选中的索引相同我们就返回,我们就可以索取所选取的商品信息了。
添加购物车