当前位置:网站首页>[applet project development -- JD mall] uni app commodity classification page (first)
[applet project development -- JD mall] uni app commodity classification page (first)
2022-07-01 02:52:00 【Computer magician】
Welcome to
Magic house !!The article contains columns
-- 2022 Wechat applet Jingdong Mall actual battle --Column content
-- uni-app Project structures, --
-- Jingdong Mall uni-app To configure tabBar & Window style --
-- Jingdong Mall uni-app Developed subcontracting configuration --
-- Jingdong Mall uni-app Developed rotation chart --
-- Jingdong Mall uni-app The classified navigation area --
-- Jingdong Mall uni-app Floor data acquisition Render the page UI --
List of articles
- One 、 newly build cate Branch ( the selected readings *)
- Two 、 Add compilation mode
- 3、 ... and 、 Render page basic structure
- 3、 ... and 、API Obtain data such as mobile phone model
- Four 、 beautify item term
- 5、 ... and 、 Get classification page data
- 6、 ... and 、 Dynamically render the first level classification page structure
One 、 newly build cate Branch ( the selected readings *)
To create a branch , It is also a good habit of project development , In this way, the open projects are in good order
You can also skip this section , It does not affect the reading impression
In the root directory , Right click to open
bash
be based on master Branch created locally cate Sub branches , Used to develop and cate Related functions :
- Create a new branch cate And jump to the branch
git checkout -b cate
View branches ( There is * Represents the current branch )
git branch

Two 、 Add compilation mode
Because what we want to develop is cate page , So we will modify the startup page in the applet compilation mode stay cate, So you don't have to click jump every time 
3、 ... and 、 Render page basic structure
- Generate basic sliding page structure
<template>
<view>
<!-- Wrap the container -->
<view class="scroll-view-container">
<!-- left container -->
<scroll-view class="scroll-view-left" scroll-y="true" style="height: 300px;">
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
</scroll-view>
<!-- On the right side container -->
<scroll-view scroll-y="true" class="scroll-view-right" style="height: 300px;">
<view></view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
<view>xxx</view>
</scroll-view>
</view>
</view>
</template>
<style lang="scss">
.scroll-view-container {
display: flex;
}
.scroll-view-left {
width: 200rpx;
}
.scroll-view-right {
}
</style>
effect :
3、 ... and 、API Obtain data such as mobile phone model
- We need to put the whole scroll-view The height of the screen is the same as that of the mobile phone , We can call API
uni.getSystemSync(), Get the information of the mobile device ( Such as mobile phone model , Available height )
Be careful : Is the usable window height , Not screen height ( barring navigationbar and tarbar)
stay onLoad() Lifecycle function calls API , And in data Node definition data , Assign the available window height to windowHeight
<script>
export default {
data() {
return {
// Current device available height
windowHeight: ''
};
},
onLoad() {
const {
windowHeight: infoSys
} = uni.getSystemInfoSync()
this.windowHeight = infoSys
}
}
Label style dynamic binding
:style="{height: windowHeight + 'px'}"
effect :
Four 、 beautify item term
- Method 1 ( Don't suggest ):
For every one item Item plus class selector
Select the label with the mouse ,CTRL + D Choose all ( The new version is CTRL + E), Such as 

In this class selector Modify the style
- Method 2 ( Suggest )
Use descendant selector , stay.scroll-view-right view{}Modify the style
Add active item style &.active( Used to configure the selected style )
style
.scroll-view-left view {
text-align: center;
line-height: 120rpx;
background-color: lemonchiffon;
font-size: 12px;
// Active item style Descendant selector overrides class selector
// & Selector override Where selector
&.active {
background-color: lawngreen;
// Relative positioning Move without changing the document layout
position: relative;
// Set the first element
&::before {
// The content is A space
content: ' ';
// Block-level elements
display: block;
background-color: #a00000;
height: 60rpx;
width: 6rpx;
// Absolute positioning Move out of the normal document stream
position: absolute;
// Far left
top: 25%;
left: 0;
}
}
}
.scroll-view-right view{
text-align: center;
line-height: 80rpx;
background-color: aquamarine;
}
Activation term
<view class="active">xxx</view>
effect :
5、 ... and 、 Get classification page data
- data Defining data
<script>
export default {
data() {
return {
// Current device available height
windowHeight: '',
// Classification page data
cateList: []
};
},
```
- onLoad Lifecycle function calls Function fetch data
...
onLoad() {
// Call the height data of the mobile phone
const {
windowHeight: infoSys
} = uni.getSystemInfoSync()
this.windowHeight = infoSys
// Retrieve classified data
this.getCateList()
},
...
- method Definition Get function
...
methods: {
// Get classified data
async getCateList() {
// async Asynchronous cannot use arrow functions
const {
data:res} = await uni.$http.get('/api/public/v1/categories')
// Judge whether the assignment is successful
if (res.meta.status != 200) return uni.$showMsg()
// assignment
this.cateList = res.message
}
}
}
</script>
To be successful 
5.1 Interface data style
{
"message": [
{
"cat_id": 1,
"cat_name": " Big appliances ",
"cat_pid": 0,
"cat_level": 0,
"cat_deleted": false,
"cat_icon": "",
"children": [
{
"cat_id": 3,
"cat_name": " TV ",
"cat_pid": 1,
"cat_level": 1,
"cat_deleted": false,
"cat_icon": "",
"children": [
{
"cat_id": 5,
"cat_name": " Curved TV ",
"cat_pid": 3,
"cat_level": 2,
"cat_deleted": false,
"cat_icon": "full/2fb113b32f7a2b161f5ee4096c319afedc3fd5a1.jpg"
}]
}
]
}
],
"meta": {
"msg": " To be successful ",
"status": 200
}
}
6、 ... and 、 Dynamically render the first level classification page structure
Activation term active Realize the idea :
stay data Node definition data
active, Dynamic loop for classification The generated index is compared with , If it is the same, add a class to the corresponding indexactive, And click "help" for classification Bind the event handler and pass the index parameter to it , Dynamic modificationactive, as follows
- Method 1 :
Component parameters
<template>
<view>
<!-- Wrap the container -->
<view class="scroll-view-container">
<!-- left container -->
<scroll-view class="scroll-view-left" scroll-y="true" :style="{height: windowHeight + 'px'}">
<!-- Judge whether to select -active -->
<block v-for="(item,index) in cateList" v-bind:key="index">
<!-- Method 1 of parameter transmission -->
<view v-bind:class="(active === index ?'active' : '')" v-on:click="activeTap" :data-active=index>{
{
item.cat_name}}</view>
</block>
</scroll-view>
<!-- On the right side container -->
<scroll-view scroll-y="true" class="scroll-view-right" :style="{height: windowHeight + 'px'}">
<view>xxx</view>
</scroll-view>
</view>
</view>
</template>
// function
// Touch event binding
activeTap(options){
this.active = options.target.dataset.active
},
- Method 2 :
Be careful : The binding function directly passes parameters , This is in Native applets are not allowed Of , Native applets treat the whole as a function
<template>
<view>
<!-- Wrap the container -->
<view class="scroll-view-container">
<!-- left container -->
<scroll-view class="scroll-view-left" scroll-y="true" :style="{height: windowHeight + 'px'}">
<!-- Judge whether to select -active -->
<block v-for="(item,index) in cateList" v-bind:key="index">
<!-- Parameter transfer method 2 Function directly passes parameters This is not possible in native applets -->
<!-- <view v-bind:class="(active === index ?'active' : '')" v-on:click="activeTap(index)" >{
{
item.cat_name}}</view> -->
</block>
</scroll-view>
<!-- On the right side container -->
<scroll-view scroll-y="true" class="scroll-view-right" :style="{height: windowHeight + 'px'}">
<view>xxx</view>
</scroll-view>
</view>
</view>
</template>
// function
// Touch event binding
activeTap(options){
// this.active = options.target.dataset.active
this.active = options
},
effect :
Thanks for reading , Your praise and collection are the biggest motivation for me to create !
边栏推荐
- Dart training and sphygmomanometer inflation pump power control DPC
- 【微信小程序開發】樣式匯總
- Gartner research: in China, the adoption of hybrid cloud has become the mainstream trend
- Sampling Area Lights
- VirtualBox installation enhancements
- Mouse over effect 8
- If I am in Beijing, where is a better place to open an account? In addition, is it safe to open a mobile account?
- Mouse over effect I
- [wechat applet development] style summary
- Detailed explanation of pointer array and array pointer (comprehensive knowledge points)
猜你喜欢

小程序自定义顶部导航栏,uni-app微信小程序自定义顶部导航栏

Pychart software deployment gray unable to point

lavaweb【初识后续问题的解决】

Go import self built package

【小程序项目开发-- 京东商城】uni-app之分类导航区域

Saving images of different depths in opencv

产业互联网中,「小」程序有「大」作为

Proxy support and SNI routing of pulsar

Restcloud ETL practice data row column conversion

Pulsar Geo Replication/灾备/地域复制
随机推荐
鼠标悬停效果四
鼠标悬停效果三
鼠标悬停效果五
【小程序项目开发 -- 京东商城】uni-app 商品分类页面(下)
Classic programming problem: finding the number of daffodils
Share Creators萌芽人才培養計劃來了!
鼠标悬停效果一
Mouse over effect 7
7_OpenResty安装
PHP batch Excel to word
How to open a stock account? Also, is it safe to open an account online?
Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and
Big orange crazy blog move notice
MCU firmware packaging Script Software
详解数据治理知识体系
Résumé des styles de développement d'applets Wechat
【小程序项目开发-- 京东商城】uni-app之首页商品楼层
园区运营效率提升,小程序容器技术加速应用平台化管理
Restcloud ETL practice to realize incremental data synchronization without identification bit
Dell服务器重启iDRAC方法


