小程序第六天总结

"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],这种形式。遍历次商品中的类型中的索引和我们选中的索引相同我们就返回,我们就可以索取所选取的商品信息了。

添加购物车

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值