您好,登錄后才能下訂單哦!
這篇文章主要介紹了微信小程序商城開發(fā)之動態(tài)API實現(xiàn)商品的詳情頁示例,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
1、實現(xiàn)商品詳情頁面布局(這篇實現(xiàn)3個模塊,頭部商品圖片輪播、商品價格和商品描述、商品詳情展示)
2、根據(jù)用戶點擊不同的商品請求API動態(tài)加載數(shù)據(jù)
訪問:https://100boot.cn/ 選擇微商城案例,如下圖所示:
下方還有詳細的數(shù)據(jù)模型可以查看哦!
上一篇還記得我們做了商品點擊查看詳情的事件采集嗎?那么再加上跳轉(zhuǎn)商品詳情頁功能,如下圖所示:
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}"> <block wx:for="{{goods.imgUrls}}"> <swiper-item> <image src="{{item}}" src="{{item}}" bindtap="previewImage" mode="widthFix"></image> </swiper-item> </block></swiper><!--商品價格和商品描述--><view><view class="product-name-wrap"> {{goods.title}} </view> <view class="product-price-wrap"> <view> <p class="product-price-new">¥{{goods.price}}</p> <p class="product-price-old">原價¥{{goods.privilegePrice}}</p> </view> </view></view> <view class="details"> <scroll-view scroll-y="true"> <text>商品詳情</text> <block wx:for-items="{{goods.detailImg}}" wx:key="name"> <image class="image_detail" src="{{item}}" mode="widthFix"/> </block> <view class="temp"></view> </scroll-view> </view>
page { display: flex; flex-direction: column; height: 100%; } /* 直接設(shè)置swiper屬性 */ swiper { /* height: 500rpx; */ height: 750rpx; } swiper-item image { width: 100%; height: 100%; } /**商品價格**/ .product-price-wrap{ display: flex; justify-content:space-between;/**兩邊對齊**/ flex-direction: row; flex-wrap: wrap; margin:5px 5px; /* border:1rpx solid red; */ } .product-price-wrap .product-price-new{ color: red; font-size: 40rpx; margin: 10rpx; } .product-price-wrap .product-price-old{ color: #888; text-decoration: line-through; padding-left: 5px; font-size: 12px; line-height:30px; font-weight:300; } .product-name-wrap{ margin: 0px 10px; font-size: 14px; color: #404040; } .details{ padding: 0 5px 0 5px; } .detail { display: flex; flex-direction: column; margin-top: 15rpx; margin-bottom: 0rpx; } .detail .title { font-size: 40rpx; margin: 10rpx; color: black; text-align: justify; height: 100rpx; } .detail .price { color: red; font-size: 40rpx; margin: 10rpx; } .line_flag { width: 80rpx; height: 1rpx; display: inline-block; margin: 20rpx auto; background-color: gainsboro; text-align: center; } .line { width: 100%; height: 2rpx; display: inline-block; margin: 20rpx 0rpx; background-color: gainsboro; text-align: center; } .detail-nav { display: flex; flex-direction: row; align-items: center; float: left; background-color: #fff; position: fixed; bottom: 0; right: 0; z-index: 1; width: 100%; height: 100rpx; } .button-green { background-color: #4caf50; /* Green */ } .button-red { background-color: #f44336; /* 紅色 */ } .button-addCar { background-color: #f44336; /* 紅色 */ width: 100%; } .image_detail { width: 100%; /* height: 750rpx; */ } .detail-nav image { width: 70rpx; height: 50rpx; margin: 20rpx 40rpx; } .line_nav { width: 5rpx; height: 100%; background-color: gainsboro; } /* 占位 */ .temp { height: 100rpx; }
const ajax = require('../../utils/ajax.js'); const utils = require('../../utils/util.js'); var imgUrls = []; var detailImg = []; var goodsId = null; var goods = null; Page({ /** * 頁面的初始數(shù)據(jù) */ data: { isLike: true, showDialog: false, goods:null, indicatorDots: true, //是否顯示面板指示點 autoplay: true, //是否自動切換 interval: 3000, //自動切換時間間隔,3s duration: 1000, // 滑動動畫時長1s }, //預(yù)覽圖片 previewImage: function (e) { var current = e.target.dataset.src; wx.previewImage({ current: current, // 當(dāng)前顯示圖片的http鏈接 urls: this.data.imgUrls // 需要預(yù)覽的圖片http鏈接列表 }) }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function (options) { var that = this; goodsId = options.goodsId; console.log('goodsId:' + goodsId); //加載商品詳情 that.goodsInfoShow(); }, goodsInfoShow: function (success) { var that = this; ajax.request({ method: 'GET', url: 'goods/getGoodsInfo?key=' + utils.key+'&goodsId=' + goodsId, success: data => { var goodsItem = data.result; for (var i = 0; i < goodsItem.shopGoodsImageList.length; i++) { imgUrls[i] = goodsItem.shopGoodsImageList[i].imgUrl; } var details = goodsItem.details.split(";"); for (var j = 0; j < details.length; j++) { detailImg[j] = details[j]; } goods = { imgUrls: imgUrls, title: goodsItem.name, price: goodsItem.price, privilegePrice: goodsItem.privilegePrice, detailImg: detailImg, imgUrl: goodsItem.imgUrl, buyRate: goodsItem.buyRate, goodsId: goodsId, count:1, totalMoney: goodsItem.price, } that.setData({ goods : goods }) console.log(goods.title) } }) }, })
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“微信小程序商城開發(fā)之動態(tài)API實現(xiàn)商品的詳情頁示例”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。