>  기사  >  위챗 애플릿  >  WeChat 미니 프로그램 몰 개발의 동적 API는 제품 세부 정보 페이지에 대한 코드를 구현합니다(1부)

WeChat 미니 프로그램 몰 개발의 동적 API는 제품 세부 정보 페이지에 대한 코드를 구현합니다(1부)

不言
不言원래의
2018-08-16 16:50:067381검색

본 글의 내용은 위챗 미니 프로그램 몰 개발에 구현된 동적 API의 코드(1부)에 대한 내용으로, 필요한 친구들이 참고할 수 있기를 바랍니다. 그것은 당신에게 도움이 될 것입니다.

효과 보기


개발 계획

1. 제품 세부 정보 페이지 레이아웃 구현(이 문서에서는 3개 모듈, 헤드 제품 이미지 캐러셀, 제품 가격 및 제품 설명, 제품 세부 정보 표시를 구현합니다.)
2 , 요청 사용자가 다양한 제품을 클릭함에 따라 데이터를 동적으로 로드하는 API

제품 세부정보 가져오기 제품 ID 기반 API 데이터 모델

방문: https://100boot.cn/ 아래 그림과 같이 마이크로몰 케이스를 선택하세요.


아래에서 자세한 데이터 모델을 보실 수 있습니다!

home.js는 제품 세부정보 이벤트에 점프를 추가합니다

이전 기사에서 세부정보를 보기 위해 제품 클릭에 대한 이벤트 수집을 했던 것을 아직도 기억하시나요? 그런 다음 아래 그림과 같이 제품 세부 정보 페이지로 이동하는 기능을 추가합니다.


detail.wxml

<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>

detail.wxss

page {  
    display: flex;  
    flex-direction: column;  
    height: 100%;
}
/* 直接设置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;
}

detail.js

const ajax = require(&#39;../../utils/ajax.js&#39;);
const utils = require(&#39;../../utils/util.js&#39;);
var imgUrls = [];  var detailImg = [];
var goodsId = null;
var goods = null;
Page({  /**
   * 页面的初始数据
   */
  data: {    
    isLike: true,    
    showDialog: false,    
    goods:null,    
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动切换
    interval: 3000, //自动切换时间间隔,3s
    duration: 1000, //  滑动动画时长1s
  },  //预览图片
  previewImage: function (e) {    
    var current = e.target.dataset.src;
    wx.previewImage({      
        current: current, // 当前显示图片的http链接  
        urls: this.data.imgUrls // 需要预览的图片http链接列表  
    })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {    
    var that = this;
    goodsId = options.goodsId;    
    console.log(&#39;goodsId:&#39; + goodsId);    //加载商品详情
    that.goodsInfoShow();
  },  
goodsInfoShow: function (success) {    
    var that = this;
    ajax.request({      
    method: &#39;GET&#39;,      
    url: &#39;goods/getGoodsInfo?key=&#39; + utils.key+&#39;&goodsId=&#39; + 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)
      }
    })
  },
})
#🎜 🎜#
관련 추천 :

위챗 미니 프로그램 몰 개발을 위한 https 프레임워크 구축 및 상하 네비게이션 구현

WeChat 미니 프로그램 몰 개발 코드 몰 홈 페이지 복지 필드 구현으로 풀다운 제한 없이 동적 API 데이터 새로 고침

위 내용은 WeChat 미니 프로그램 몰 개발의 동적 API는 제품 세부 정보 페이지에 대한 코드를 구현합니다(1부)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.