关于组件传值

6 篇文章 0 订阅
这段代码展示了如何在微信小程序中处理商品卡片数据,包括图片懒加载、商品名称、价格和数量的显示。通过getters函数获取值,并根据useMap和valueMap进行映射。商品卡片包含爆炸文本、店铺图片、名称、代码、价格和数量等关键信息。
摘要由CSDN通过智能技术生成
 result = result.map((item) => {
                            return {
                                values: {
                                    shopImg: item.returnRequestEntryDTOList[0].picUrl,
                                },
                                ...item,
                            };
                        });

 

 <wxs src="./index.wxs" module="computed" />
<view class="card-main content-class" wx:if="{{useMain}}">
        <view class="card-left">
            <view class="card-img-box">
                <image
                    catch:tap="handleClickImg"
                    lazy-load="{{true}}"
                    class="card-img"
                    src="{{computed.getters('shopImg',values,valueMap,useMap)}}"
                    data-url="{{computed.getters('shopImg',values,valueMap,useMap)}}"
                    data-imgs="{{computed.getters('imgs',values,valueMap,useMap)}}"
                    mode="widthFix"
                />
                <view class="content-class-explosion" wx:if="{{explosionText}}">{{explosionText}}</view>
            </view>
            <view class="card-name-box">
                <slot name="info" wx:if="{{useInfoSlotMain}}"></slot>
                <view class="card-name" wx:else>{{computed.getters("shopName",values,valueMap,useMap)}}</view>
                <slot name="code" wx:if="{{useCodeSlotMain}}"></slot>
                <block wx:else>
                    <view class="card-number">{{mainTitle}}{{computed.getters("shopCode",values,valueMap,useMap)}}</view>
                    <view class="card-number">{{purchaseAgent}}{{computed.getters("purchaser",values,valueMap,useMap)}}</view>
                    <view class="card-number">{{purchaseAccount}}{{computed.getters("purchaseNumber",values,valueMap,useMap)}}</view>
                </block>
            </view>
        </view>
        <view class="card-right content-price-class">
            <view class="card-price">{{computed.getters("shopPrice",values,valueMap,useMap)}}</view>
            <view class="card-num">{{computed.getters("shopNum",values,valueMap,useMap)}}</view>
        </view>
    </view>



function getters(key, values, map, flag) {
    return !flag ? values[key] : values[map[key]];
}
module.exports = {
    getters: getters,
};


base-card-shop的js

 useMap: {
            type: Boolean,
            value: true,
        },
 valueMap: {
            type: Object,
            value: {
                titleVal: "code",
                time: "time",
                footTitle: "total",
                footVal: "value",
                stateInfo: "name",
                stateVal: "state",
                shopName: "shopName",
                shopCode: "shopCode",
                shopImg: "shopImg",
                shopPrice: "shopPrice",
                shopNum: "shopNum",
                imgs: [],
                purchaser: "purchaser",
                purchaseNumber: "purchaseNumber",
            },
        },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值