当前位置:网站首页>[applet project development -- Jingdong Mall] classified navigation area of uni app
[applet project development -- Jingdong Mall] classified navigation area of uni app
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 ( Before using the following articles strong Suggest Eat the article first )
-- 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 --
List of articles
Achieve the goal :
One 、 encapsulation uni.$showMsg()
- Development scenarios
In the project , We often need to retrieve data many times , And when the data request fails , You often need to call uni.showToast({ /* Configuration object */ }) Method to prompt the user . here , You can encapsulate one globally uni.$showMsg() Method , To simplify the uni.showToast() Method call .
The specific transformation steps are as follows :
stay main.js Project entry file , by uni Mount one $showMsg() Method ,$ Represents a custom mount function
On the function, the assignment parameter is used =, stay showToast Function is a dictionary , The assignment inside is :
// mount uni Request data message prompt Method ( Default )
uni.$showMsg = function(title = ' Data loading error ...', duration = 1500,icon = 'fail' ) {
uni.showToast({
title,
duration,
icon
})
}
The encapsulated code be used for home page ,
onLoad() {
// Retrieval method , Get the data of the carousel
this.getSwiperList()
},
methods: {
async getSwiperList() {
// '/' The root directory is in main.js File configuration baseUrl
const res = await uni.$http.get('/api/public/v1/home/swiperdata')
// Data retrieval failed
if (res.data.meta.status != 200) return uni.$showMsg()
// Data to be called assignment
this.swiperList = res.data.message
uni.$showMsg(' Data request successful !', 'success')
}
}
# One 、 Get classified navigation data
Response data reference
```cpp
{
"message": [
{
"image_src": "https://www.zhengzhicheng.cn/pyg/banner1.png",
"open_type": "navigate",
"goods_id": 129,
"navigator_url": "/pages/goods_detail/main?goods_id=129"
},
{
"image_src": "https://www.zhengzhicheng.cn/pyg/banner2.png",
"open_type": "navigate",
"goods_id": 395,
"navigator_url": "/pages/goods_detail/main?goods_id=395"
},
{
"image_src": "https://www.zhengzhicheng.cn/pyg/banner3.png",
"open_type": "navigate",
"goods_id": 38,
"navigator_url": "/pages/goods_detail/main?goods_id=38"
}
],
"meta": {
"msg": " To be successful ", "status": 200 }
}
Two 、 Get classified navigation data
- stay data Node definition
navListdata
data() {
return {
// Carousel chart array
swiperList: [],
// Category navigation array
navList: []
};
- stay method Define the data retrieval function
getNavList()
async getNavList(){
// Call data
const res = await uni.$http.get('/api/public/v1/home/catitems')
// If the call fails Return an error message and exit
if(res.data.meta.status != 200 ) return uni.$showMsg()
// assignment
this.navList = res.data.message
uni.$showMsg(' Data loaded successfully ','success')
}
}
- In the life cycle function onload Call function
getNavList()
onLoad() {
// Retrieval method , Get the data of the carousel
this.getSwiperList(),
// Get classified navigation data
this.getNavList()
},
Successfully retrieved 
3、 ... and 、 Classified navigation UI structure
Attribute nodes that need cyclic labels need to be preceded by : The prompt is followed by a variable or variable expression
3.1 Don't step on the big pit !!!
- Tai Keng 1 : Use vue-for Dynamic looping chart array , Cyclic dynamic binding requires that the label attribute node be preceded by
:(:yesv-bind:Abbreviation , That is, dynamically binding data , Then there are variables or variable expressions , If there is no colon, it is a string , At this time, the cycle cannot display the effect normally 、) - Keng two : stay UI Rendering template The template must have a label view Wrap it all up , Otherwise, the following error will be reported :
Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <style>, as they will not be parsed.
This is because there must be one in the template The root node , Take this root node as the entry , Recursively traverse each Leaf ( Child tags )
<!-- Templates -->
<template>
<view>
<!-- Rendering the carousel UI structure -->
<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
<!-- similar python for i,j in object Get the corresponding item i And index j -->
<swiper-item v-for="(item,i) in swiperList" :key="i">
<navigator class="swiper-item" :url="'/subpackages/goods_detail/goods_detail?good_id=' + item.goods_id">
<image :src="item.image_src"></image>
</navigator>
</swiper-item>
</swiper>
<view class="nav_list">
<view class="nav_item" v-for="(item,index) in navList" :key="index">
<image :src="item.image_src" class="nav_image"></image>
</view>
</view>
</view>
</template>
<!-- style -->
<style lang="scss">
.nav_list {
display: flex;
}
.nav_item{
display: flex;
width: 25%;
height: 200rpx;
justify-content: center;
align-items: center;
}
.nav_image {
width: 150rpx;
height:150rpx;
}
</style>
During development, the page can be copied to the column , Develop style and structure 
effect :
Four 、 Click the classification option to jump to the classification page
Antecedents feed :
monitor DOM(document object model) The incident happened in vue Use in
v-on:, Listening for events in an applet development tool isbind[’ state ‘], Such as :bindtap, But due to binding eventsv-on:Often need to be used , So use@Asv-on:Abbreviation ( As mentioned earlierv-bind:Is the same:narrow , This is dynamic rendering data , Small program development tools are based onmustachegrammar{ {}}Rendering data
Because of the need to Option to determine whether it is a classification option , therefore Can not simply say view Change it to navigator, You need to listen for click events , Do more complicated operations .
// Method
methods: {
// Classified navigation -- classification
navClickHandelr(item){
if (item.name === ' classification ') {
uni.switchTab({
url: "/pages/cate/cate"
})
}
},
<!--UI structure --!>
<view class="nav_list">
<!-- The ginseng item--!>
<view class="nav_item" v-for="(item,index) in navList" :key="index" v-on:click="navClickHandelr(item)">
<image :src="item.image_src" class="nav_image"></image>
</view>
</view>
effect :
Successful implementation !
Thanks for reading , Your praise and collection are the biggest motivation for me to create !
边栏推荐
- Mouse over effect III
- Sampling Area Lights
- Optimal transport Series 1
- 【PR #5 A】双向奔赴(状压DP)
- Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and
- Od modify DLL and exe pop-up contents [OllyDbg]
- Restcloud ETL practice to realize incremental data synchronization without identification bit
- Communication protocol -- Classification and characteristics Introduction
- ipmitool下载地址和编译安装时可能出现的问题
- ssh配置免密登录时报错:/usr/bin/ssh-copy-id: ERROR: No identities found 解决方法
猜你喜欢

VirtualBox installation enhancements

Restcloud ETL WebService data synchronization to local

Nacos configuration center tutorial

在unity中使用jieba分词的方法

Applet custom top navigation bar, uni app wechat applet custom top navigation bar

UE4渲染管线学习笔记

pycharm 软件deployment 灰色 无法点

STM32 - DS18B20 temperature sampling of first-line protocol

Detailed explanation of pointer array and array pointer (comprehensive knowledge points)

【小程序项目开发-- 京东商城】uni-app之分类导航区域
随机推荐
【微信小程序開發】樣式匯總
Viewing JVM parameters
集群方法同步执行框架 Suona
Mouse over effect III
Map array function
A small document of JS method Encyclopedia
鼠标悬停效果九
Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
How to open a stock account? Also, is it safe to open an account online?
鼠标悬停效果二
Is it safe to open an account online in a small securities firm? Will my money be unsafe?
Borrowing constructor inheritance and composite inheritance
Restcloud ETL WebService data synchronization to local
Add / delete / modify query summary insert/create/put/add/save/post, delete/drop/remove, update/modify/change, select/get/list/find
js 找出两个数组中的重复元素
Gartner研究:在中国,混合云的采用已成为主流趋势
Xception学习笔记
Applet custom top navigation bar, uni app wechat applet custom top navigation bar
PTA 1016
Lenovo x86 server restart management controller (xclarity controller) or TSM method
