拼接的链接,跳转到列表页,需求:取到拼接的coupon_id将它带到列表页中

本文介绍了一种在原有API请求基础上,通过添加特定参数来优化数据获取的方法。具体地,通过在/index.php接口后添加&coupon_id=coupon_id,实现了更精准的数据请求。此外,还提供了如何在列表页中声明和传递此参数的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

列表中api请求,原本的接口 /index.php?m=Home&c=api.Goods&a=goodsList
需要加上&coupon_id=coupon_id 即为
/index.php?m=Home&c=api.Goods&a=goodsList&coupon_id=coupon_id

export const goods_lists = (params) => {
  return http.fetchPost(`${baseUrl}/index.php?m=Home&c=api.Goods&a=goodsList&coupon_id=coupon_id`, params)
}

在列表页中
data 里面声明下 coupon_id: '',
created() 里将数据通过路由的形式 this.paramer.coupon_id = this.$route.query.coupon_id;
这样既可以将需要的id带到请求中,请求到需要的数据
用paramer传数据也是这样操作

以下代码中描述页面跳转时传输了哪些数据,作用是什么<view class=“location” @click=“navigateToCitySelect”> 广州从化 <view class=“search-box” @click=“navigateToSearch”> 搜索商家、美食… <view class="content" :style="{ marginTop: (statusBarHeight + 50) + 'px' }"> <swiper class="swiper" indicator-dots autoplay circular> <swiper-item v-for="(item, index) in banners" :key="index"> <image :src="item.image" mode="aspectFill" class="swiper-image"></image> </swiper-item> </swiper> <view class="coupon-banner" @click="navigateToCoupon"> <uni-icons type="notification-filled" size="24" color="#fff"></uni-icons> <view class="coupon-text"> <text class="coupon-title">新用户专享红包</text> <text class="coupon-desc">最高立减20元,点击立即领取</text> </view> <uni-icons type="arrowright" size="20" color="#fff"></uni-icons> </view> <view class="category-container"> <scroll-view scroll-x class="category-scroll"> <view v-for="(category, index) in categories" :key="index" class="category-item" @click="navigateToCategory(category.id)" > <view class="category-icon" :style="{ backgroundColor: category.color }"> <uni-icons :type="category.icon" size="30" color="#fff"></uni-icons> </view> <text class="category-name">{{ category.name }}</text> </view> </scroll-view> </view> <view class="section-title"> <text>推荐商家</text> <text class="more-link" @click="navigateToAllStores">查看更多 ></text> </view> <view class="store-list"> <view v-for="(store, index) in stores" :key="index" class="store-item" @click="navigateToStore(store.id)" > <image class="store-image" :src="store.image" mode="aspectFill"></image> <view class="store-info"> <view class="store-name"> <text>{{ store.name }}</text> <text class="min-price">¥{{ store.minPrice }}起送</text> </view> <view class="store-tags"> <text class="tag" v-for="(tag, i) in store.tags" :key="i">{{ tag }}</text> </view> <view class="store-detail"> <view> <uni-rate :value="store.rating" size="14" disabled></uni-rate> <text class="rating">{{ store.rating }}</text> <text>月售{{ store.monthlySales }}单</text> </view> <text>{{ store.distance }} | {{ store.deliveryTime }}分钟</text> </view> </view> </view> </view> </view> </view> </template> <script> export default { data() { return { statusBarHeight: 0, banners: [ { image: '/static/l1.jpg', }, { image: '/static/l2.jpg',}, { image: '/static/s.jpg', } ], categories: [ { id: 1, name: '美食', icon: 'shop', color: '#FF5A5F' }, { id: 2, name: '超市', icon: 'cart', color: '#0085FF' }, { id: 3, name: '甜品', icon: 'star', color: '#FF5A5F' }, { id: 4, name: '早餐', icon: 'circle', color: '#FFAA00' }, { id: 5, name: '火锅', icon: 'fire', color: '#FF5A5F' }, { id: 6, name: '轻食', icon: 'heart', color: '#34C759' } ], stores: [ { id: 1, name: '肯德基宅急送', image: '/static/ks.jpg', minPrice: 20, tags: ['品牌', '满减', '折扣'], rating: 4.8, monthlySales: 3245, distance: '1.2km', deliveryTime: 30 }, { id: 2, name: '麦当劳麦乐送', image: '/static/ms.jpeg', minPrice: 25, tags: ['品牌', '优惠券', '折扣'], rating: 4.7, monthlySales: 2987, distance: '0.8km', deliveryTime: 25 }, { id: 3, name: '必胜客宅急送', image: '/static/bs.png', minPrice: 50, tags: ['品牌', '新品', '满减'], rating: 4.6, monthlySales: 1876, distance: '1.5km', deliveryTime: 35 } ] } }, onLoad() { const systemInfo = uni.getSystemInfoSync(); this.statusBarHeight = systemInfo.statusBarHeight; }, methods: { navigateToSearch() { uni.showToast({ title: '跳转到搜索页面', icon: 'none' }) uni.navigateTo({ url: '/pages/category/search' }) }, navigateToCitySelect() { uni.showToast({ title: '选择城市', icon: 'none' }) }, navigateToProfile() { uni.switchTab({ url: '/pages/profile/profile' }) }, navigateToCoupon() { uni.showToast({ title: '跳转到优惠券页面', icon: 'none' }) uni.navigateTo({ url: '/pages/category/discount' }) }, navigateToCategory(id) { const categoryPages = { 1: '/pages/category/food', // 2: '/pages/category/supermarket', // 3: '/pages/category/dessert', // 4: '/pages/category/breakfast', // 5: '/pages/category/hotpot', // 6: '/pages/category/lightfood' }; if (categoryPages[id]) { uni.navigateTo({ url: categoryPages[id] }); } else { uni.showToast({ title: '页面正在开发中', icon: 'none' }); } }, navigateToAllStores() { uni.navigateTo({ url:'/pages/category/allstores' }) } } } </script> <style> page { background-color: #f5f5f5; color: #333; font-size: 28rpx; line-height: 1.5; } .container { background-color: #fff; min-height: 100vh; padding-bottom: 120rpx; position: relative; } .custom-navbar { position: fixed; top: 0; left: 0; right: 0; z-index: 100; background: linear-gradient(90deg, #0085ff, #0af); } .nav-content { display: flex; align-items: center; justify-content: space-between; padding: 10rpx 30rpx; height: 90rpx; } .location { display: flex; align-items: center; font-size: 32rpx; font-weight: bold; color: white; } .city-name { margin: 0 8rpx; max-width: 150rpx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .search-box { flex: 1; margin: 0 30rpx; background: rgba(255, 255, 255, 0.8); border-radius: 50rpx; height: 70rpx; display: flex; align-items: center; padding: 0 25rpx; color: #666; } .search-box text { margin-left: 10rpx; font-size: 28rpx; } .content { padding: 20rpx; } .swiper { height: 320rpx; border-radius: 20rpx; overflow: hidden; box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1); } .swiper-image { width: 100%; height: 100%; } .coupon-banner { margin: 30rpx 0; background: linear-gradient(90deg, #ff5e3a, #ff9500); border-radius: 16rpx; padding: 20rpx 25rpx; color: white; display: flex; align-items: center; box-shadow: 0 6rpx 12rpx rgba(255, 94, 58, 0.2); } .coupon-text { flex: 1; display: flex; flex-direction: column; margin-left: 20rpx; } .coupon-title { font-size: 32rpx; font-weight: bold; margin-bottom: 8rpx; } .coupon-desc { font-size: 24rpx; opacity: 0.9; } .category-container { background: #fff; padding: 20rpx 0 30rpx; border-radius: 20rpx; margin-bottom: 30rpx; box-shadow: 0 5rpx 15rpx rgba(0, 0, 0, 0.05); } .category-scroll { white-space: nowrap; width: 100%; padding: 0 10rpx; } .category-item { display: inline-flex; flex-direction: column; align-items: center; width: 150rpx; margin: 0 10rpx; } .category-icon { width: 100rpx; height: 100rpx; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 15rpx; } .category-name { font-size: 26rpx; color: #666; white-space: nowrap; text-align: center; } .section-title { padding: 20rpx 0; font-size: 36rpx; font-weight: bold; display: flex; justify-content: space-between; align-items: center; } .more-link { font-size: 26rpx; color: #999; font-weight: normal; } .store-list { padding-bottom: 30rpx; } .store-item { background: #fff; border-radius: 20rpx; overflow: hidden; margin-bottom: 30rpx; box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.08); transition: transform 0.3s ease; } .store-item:active { transform: scale(0.98); } .store-image { width: 100%; height: 300rpx; } .store-info { padding: 20rpx; } .store-name { font-size: 32rpx; font-weight: bold; margin-bottom: 10rpx; display: flex; justify-content: space-between; } .min-price { color: #FF5A5F; font-weight: bold; } .store-tags { display: flex; margin-bottom: 15rpx; flex-wrap: wrap; } .tag { font-size: 22rpx; padding: 4rpx 12rpx; border-radius: 6rpx; margin-right: 10rpx; margin-bottom: 8rpx; background: #fff0f0; color: #ff5a5f; } .store-detail { display: flex; justify-content: space-between; align-items: center; font-size: 26rpx; color: #666; padding-top: 15rpx; border-top: 1rpx dashed #eee; } .rating { color: #ffaa00; font-weight: bold; margin: 0 10rpx; } .tabbar { position: fixed; bottom: 0; left: 0; right: 0; height: 100rpx; background: white; display: flex; box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1); z-index: 100; border-top: 1rpx solid #eee; } .tab-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22rpx; color: #999; } .tab-item.active { color: #0085ff; } .tab-item text { margin-top: 6rpx; } </style>
最新发布
06-23
{ "errcode": 0, "errmsg": "ok", "order": { "order_id": "37423523451235145", "status": 20, "create_time": 1658505600, "update_time": 1658505600, "order_detail": { "product_infos": [ { "product_id": 234245, "sku_id": 23424, "sku_cnt": 10, "on_aftersale_sku_cnt": 10, "finish_aftersale_sku_cnt": 0, "title": "健身环", "thumb_img": "https://mmecimage.cn/p/wx37f38d59298839c3/HJE9eJaEc5bJk-eaArVdILSB7MMaHgdK2-JIn51nMQ", "sale_price": 2000, "market_price": 2000, "sku_attrs": [ { "attr_key": "产地", "attr_value": "四川成都" }, { "attr_key": "材质", "attr_value": "玻璃" }, { "attr_key": "适用人群", "attr_value": "青年;中年" }, { "attr_key": "数量", "attr_value": "33" }, { "attr_key": "精度", "attr_value": "3.001" }, { "attr_key": "重量", "attr_value": "38 mg" }, { "attr_key": "毛重", "attr_value": "380 kg" } ] } ], "pay_info": { "prepay_id": "42526234625", "transaction_id": "131456479687", "prepay_time": 1658509200, "pay_time": 1658509200, "payment_method":1 }, "price_info": { "product_price": 20000, "order_price": 10500, "freight": 500, "discounted_price": 10000, "is_discounted": true }, "delivery_info": { "address_info": { "user_name": "陈先生", "postal_code": "2435245", "province_name": "广东", "city_name": "广州", "county_name": "海珠区", "detail_info": "大塘", "tel_number": "24534252" }, "delivery_product_info": [ { "waybill_id": "134654612313", "delivery_id": "STO", "delivery_time": 1620738080, "deliver_type": 1, "product_infos": [ { "product_id": "234245", "sku_id": "23424", "product_cnt": 1 } ] } ], "ship_done_time": 1620738080, "deliver_method":0 }, "coupon_info":{ "user_coupon_id":"301234567890" }, "ext_info": { "customer_notes": "发顺丰", "merchant_notes": "库存不足,取消", "finder_id": "sph3FZbOEY46mAB", "live_id": "export/UzFfAgtgekIEAQAAAAAAt40WWe5njQAAAAstQy6ubaLX4KHWvLEZgBPE5KNoYRJdUeaEzNPgMJq4tEJ8QSCaA2N_Iua2abcd", "order_scene": 2 }, "sharer_info":{ "sharer_openid": "SHAREROPENID", "sharer_unionid": "SHARERUNIONID", "sharer_type": 1, "share_scene": 1, "handling_progress": 1 }, "settle_info":{ "commission_fee" : 10, "predict_commission_fee": 10 }, "sku_sharer_infos":[ { "sharer_openid": "SHAREROPENID", "sharer_unionid": "SHARERUNIONID", "sharer_type": 1, "share_scene": 1, "sku_id": "23424" } ] }, "aftersale_detail": { "aftersale_order_list": [ { "aftersale_order_id": "1234", "status": 13 } ], "on_aftersale_order_cnt": 1 }, "openid": "OPENID"
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值