這篇文章將為大家詳細講解有關(guān)微信小程序中如何使用動態(tài)API把商城項目的商品進行分類,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián)專注于通榆網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供通榆營銷型網(wǎng)站建設(shè),通榆網(wǎng)站制作、通榆網(wǎng)頁設(shè)計、通榆網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造通榆網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供通榆網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
看效果
商品分類API.jpg
下方還有詳細的數(shù)據(jù)模型可以查看哦!
classify.wxml
<!--主盒子-->
<view class="container">
<!--左側(cè)欄-->
<view class="nav_left">
<block wx:for="{{classifyItems}}">
<!--當前項的id等于item項的id,那個就是當前狀態(tài)-->
<!--用data-index記錄這個數(shù)據(jù)在數(shù)組的下標位置,使用data-id設(shè)置每個item的id值,供打開2級頁面使用-->
<view class="nav_left_items {{curNav == item.id ? 'active' : ''}}" bindtap="switchRightTab" data-index="{{index}}" data-id="{{item.id}}">
{{item.name}}
</view>
</block>
</view>
<!--右側(cè)欄-->
<view class="nav_right">
<!--如果有數(shù)據(jù),才遍歷項-->
<view wx:if="{{classifyItems[curIndex].ishaveChild}}">
<block wx:for="{{classifyItems[curIndex].shopClassifyDtoList}}">
<view class="nav_right_items">
<!--界面跳轉(zhuǎn) -->
<navigator url="/pages/classifyGoods/classifyGoods?classifyId={{item.id}}">
<image src="{{item.imgUrl}}"></image>
<text>{{item.name}}</text>
</navigator>
</view>
</block>
</view>
<!--如果無數(shù)據(jù),則顯示數(shù)據(jù)-->
<view class="nodata_text" wx:else>該分類暫無數(shù)據(jù)</view>
</view>
</view>classify.wxss
/* pages/classify/classify.wxss */
page{
background: #f5f5f5;
}
/*總體主盒子*/
.container {
position: relative;
width: 100%;
height: 100%;
background-color: #fff;
color: #939393;
}
/*左側(cè)欄主盒子*/
.nav_left{
/*設(shè)置行內(nèi)塊級元素*/
position: absolute;
/* display: inline-block; */
width: 25%;
height: 100%;
/*主盒子設(shè)置背景色為灰色*/
background: #f5f5f5;
text-align: center;
left: 0;
top:0;
}
/*左側(cè)欄list的item*/
.nav_left .nav_left_items{
height: 40px;
line-height: 40px;
padding: 6px 0;
border-bottom: 1px solid #dedede;
font-size: 14px;
}
/*左側(cè)欄list的item被選中時*/
.nav_left .nav_left_items.active{
/*背景色變成白色*/
background: #fff;
color: #f0145a;
}
/*右側(cè)欄主盒子*/
.nav_right{
/*右側(cè)盒子使用了絕對定位*/
position: absolute;
top: 0;
right: 0;
flex: 1;
/*寬度75%,高度占滿,并使用百分比布局*/
width: 75%;
height: 1000px;
padding: 10px;
box-sizing: border-box;
background: #fff;
}
/*右側(cè)欄list的item*/
.nav_right .nav_right_items{
/*浮動向左*/
float: left;
/*每個item設(shè)置寬度是33.33%*/
width: 33.33%;
height: 120px;
text-align: center;
}
.nav_right .nav_right_items image{
/*被圖片設(shè)置寬高*/
width: 60px;
height: 60px;
margin-top: 15px;
}
.nav_right .nav_right_items text{
/*給text設(shè)成塊級元素*/
display: block;
margin-top: 15px;
font-size: 14px;
color: black;
/*設(shè)置文字溢出部分為...*/
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.nodata_text
{
color: black;
font-size: 14px;
text-align: center;
}
.left_cate {
display: flex;
flex-direction: row;
/*每個高30px*/
height: 40px;
/*垂直居中*/
line-height: 40px;
/*再設(shè)上下padding增加高度,總高42px*/
padding: 6px 0;
/*只設(shè)下邊線*/
border-bottom: 1px solid #dedede;
/*文字14px*/
font-size: 14px;
background: #fff;
color: #f0145a;
}
.separate {
background-color: #f0145a;
width: 10rpx;
z-index: 10;
}classify.js
const ajax = require('../../utils/ajax.js');
const utils = require('../../utils/util.js');
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
classifyItems:[],
curNav: 1,
curIndex: 0
},
//事件處理函數(shù)
switchRightTab: function (e) {
// 獲取item項的id,和數(shù)組的下標值
let id = e.target.dataset.id,
index = parseInt(e.target.dataset.index);
// 把點擊到的某一項,設(shè)為當前index
this.setData({
curNav: id,
curIndex: index
})
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
var that = this;
that.classifyShow();
},
classifyShow: function (success) {
var that = this;
ajax.request({
method: 'GET',
url: 'classify/getShopClassifyList?key=' + utils.key,
success: data => {
that.setData({
classifyItems: data.result
})
console.log(data.result)
}
})
},
})關(guān)于“微信小程序中如何使用動態(tài)API把商城項目的商品進行分類”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
網(wǎng)站欄目:微信小程序中如何使用動態(tài)API把商城項目的商品進行分類
標題來源:http://chinadenli.net/article16/jggpgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站收錄、外貿(mào)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、虛擬主機、移動網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)