溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

微信小程序商城開發(fā)之商城首頁輪播圖、商品分類導(dǎo)航以及新品特賣如何實現(xiàn)

發(fā)布時間:2021-01-28 14:07:05 來源:億速云 閱讀:330 作者:小新 欄目:移動開發(fā)

這篇文章主要介紹了微信小程序商城開發(fā)之商城首頁輪播圖、商品分類導(dǎo)航以及新品特賣如何實現(xiàn),具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

實現(xiàn)功能模塊

微信小程序商城開發(fā)之商城首頁輪播圖、商品分類導(dǎo)航以及新品特賣如何實現(xiàn)

主要實現(xiàn)2、3、4,用到的API數(shù)據(jù)服務(wù)如下圖所示:

微信小程序商城開發(fā)之商城首頁輪播圖、商品分類導(dǎo)航以及新品特賣如何實現(xiàn)

首頁輪播模塊實現(xiàn)
home.js
<!--首頁輪播 banner -->
    <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
    <block wx:for="{{banners}}">
      <swiper-item>
        <image src="{{item.imgUrl}}" mode="widthFix"/>
      </swiper-item>
    </block>
  </swiper>
home.wxss
/* 直接設(shè)置swiper屬性 */
swiper {  
    height: 300rpx;
}
swiper-item image {  
    width: 100%;  height: 100%;
}
home.js

頁面初始化輪播數(shù)據(jù)

data: {
    navbars:null,//接上篇導(dǎo)航初始化數(shù)據(jù)
    currentTab: 0,//接上篇導(dǎo)航初始化數(shù)據(jù)
    banners:null,
    indicatorDots: true, //是否顯示面板指示點
    autoplay: true, //是否自動切換
    interval: 3000, //自動切換時間間隔,3s
    duration: 1000, //  滑動動畫時長1s
  },

頁面初始化加載輪播數(shù)據(jù)函數(shù)

/**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */

onLoad: function (options) {    
    var that = this;    //加載navbar導(dǎo)航條,接上篇導(dǎo)航數(shù)據(jù)
    that.navbarShow();   //加載banner輪播
    that.bannerShow();
  },

ajax獲取輪播數(shù)據(jù)

bannerShow: function (success) {    
    var that = this;
    ajax.request({      
        method: 'GET',      
        url: 'home/banners?key=' + utils.key,      
        success: data => {
        that.setData({          
            banners: data.result
        })        
        console.log(data.result)
      }
    })
  },
首頁分類導(dǎo)航實現(xiàn)
home.js
<!-- 分類導(dǎo)航 -->
 <view>
  <view class="navy">
    <block wx:for-items="{{menus}}" wx:key="name">
      <view class="nav-item"  data-type="{{item.menuName}}" data-typeid="{{item.id}}">
        <image src="{{item.imgUrl}}" class="nav-image" />
        <text>{{item.menuName}}</text>
      </view>
    </block>
  </view>
 </view>
home.wxss
/*=================分類導(dǎo)航====================*/
.navs {  
    display: flex; 
    justify-content: left; 
    flex-direction: row;  
    flex-wrap: wrap;  
}
.nav-item {  
    width: 25%;  
    display: flex;  
    align-items: center;  
    flex-direction: column; 
    /* padding: 20rpx; */
    padding-top: 20rpx;
}
.nav-item .nav-image {  
    width: 80rpx;  
    height: 80rpx;  /* border-radius: 50%;設(shè)置邊界圓角 */
}
.nav-item text {  
    padding-top: 20rpx;  
    font-size: 25rpx;
}
home.js

頁面初始化分類導(dǎo)航數(shù)據(jù)

data: {
    navbars:null,//導(dǎo)航數(shù)據(jù)
    currentTab: 0,
    banners:null, //輪播數(shù)據(jù)
    indicatorDots: true, //是否顯示面板指示點
    autoplay: true, //是否自動切換
    interval: 3000, //自動切換時間間隔,3s
    duration: 1000, //  滑動動畫時長1s
    menus: null, //分類導(dǎo)航數(shù)據(jù)},

頁面初始化加載分類導(dǎo)航數(shù)據(jù)函數(shù)

/**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (options) {    
    var that = this;    //加載navbar導(dǎo)航條
    that.navbarShow();    //加載banner輪播
    that.bannerShow();    //加載menu分類導(dǎo)航菜單
    that.menuShow();
  },

ajax獲取分類導(dǎo)航數(shù)據(jù)

menuShow: function (success) {    
    var that = this;
    ajax.request({      
    method: 'GET',      
    url: 'home/menus?key='+ utils.key,      
    success: data => {
        that.setData({          
            menus: data.result
        })        
        console.log(data.result)
      }
    })
  },
首頁新品特賣模塊實現(xiàn)
home.js
<view class="separate"></view>
<view class="cate-container"> 
    <view class="category-title">
      <text class="name">新品特賣</text>
      <view class="line_flag"></view>
      <block wx:for-items="{{brands}}" wx:key="id">
        <navigator url="/pages/detail/detail">
        <image class="head-img" src="{{item.imgUrl}}" mode="widthFix"></image>
        </navigator>
        <text class="brand-name">{{item.name}}</text> 
        <view class='pas'>
        <image class="activity-logo" src="../../images/activity_logo.png" mode="widthFix"></image>
        {{item.remark}}        </view>
      </block> 
    </view>     
  </view>
home.wxss
/*=================新品特賣 樣式====================*/
  .category-title {  
    display: flex;  
    flex-direction: column;  
    margin-top: 20rpx;  
    margin-bottom: 0rpx;  
    padding: 0px 10px;
  
} 
 .category-title .title{  
    font-size: 14px;  
    font-weight:900;
} 

.category-title .line_name{  
    font-size: 10px;  
    color: #98989f;  
    display: flex;  
    justify-content:space-between;

} 
/* 分割線 */

.separate {  
    height: 15rpx;  
    background-color: #f2f2f2;
}
.category-title {  
    display: flex;  
    flex-direction: column;  
    margin-top: 25rpx;  
    margin-bottom: 0rpx;
}
.category-title .name {  
    font-size: 40rpx;  
    text-align: center;  
    margin: 10rpx auto;
}
.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;
}
.head-img {  
    width: 100%;
}
.brand-name{  
    font-weight: 600; 
    font-size: 32rpx;
}  
.activity-logo {  
    width:35rpx;  
    height:35rpx;  
    margin-right: 10rpx;  /* position: absolute; */

}
.pms{  
    font-size: 28rpx;  
    margin-bottom: 20rpx;  
    display: flex; 
    justify-content: left; 
    flex-direction: row;  color: #5771a8;
}
home.js

頁面初始化新品特賣數(shù)據(jù)

data: {
    navbars:null,//導(dǎo)航數(shù)據(jù)
    currentTab: 0,
    banners:null, //輪播數(shù)據(jù)
    indicatorDots: true, //是否顯示面板指示點
    autoplay: true, //是否自動切換
    interval: 3000, //自動切換時間間隔,3s
    duration: 1000, //  滑動動畫時長1s
    menus: null, //分類導(dǎo)航數(shù)據(jù)
    brands: null, //新品特賣數(shù)據(jù)},

頁面初始化加載新品特賣數(shù)據(jù)函數(shù)

/**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (options) {    
    var that = this;    //加載navbar導(dǎo)航條
    that.navbarShow();    //加載banner輪播
    that.bannerShow();    //加載menu分類導(dǎo)航菜單
    that.menuShow();   //加載新品特賣
    that.brandShow();
  },

ajax獲取新品特賣數(shù)據(jù)

brandShow: function (success) {    
var that = this;
    ajax.request({      
        method: 'GET',      
        url: 'activity/brands?  key='+utils.key+'&type=temai&page=1&size=5',      
        success: data => {
        that.setData({          
            brands: data.result.list
        })        
            console.log("brands:" + data.result.list)
      }
    })
  },
實現(xiàn)效果預(yù)覽

微信小程序商城開發(fā)之商城首頁輪播圖、商品分類導(dǎo)航以及新品特賣如何實現(xiàn)

備注:本文是為了更好的讓大家能夠有模塊化的思維來實現(xiàn)改電商案例,后續(xù)依然會采用這種方式,因為更貼近與實際工作場景,也讓自己的編碼更加的規(guī)范增加可閱讀性。

感謝你能夠認真閱讀完這篇文章,希望小編分享的“微信小程序商城開發(fā)之商城首頁輪播圖、商品分類導(dǎo)航以及新品特賣如何實現(xiàn)”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細節(jié)

免責(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)容。

AI