当前位置:网站首页>[small program project development -- Jingdong Mall] rotation chart of uni app development
[small program project development -- Jingdong Mall] rotation chart of uni app development
2022-06-22 17:53:00 【Computer magician】

Preface
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 —
List of articles
One 、 newly build tabBar 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 home Sub branches , Used to develop and home Related functions :
git checkout -b home
View branches ( There is * Represents the current branch )
git branch

Two 、 Configure network requests
Due to the limitation of the platform , Not supported in applet projects axios, And the original wx.request() API The function is relatively simple , Global customization functions such as interceptors are not supported . therefore , It is suggested that uni-app Project use
@escook/request-miniprogramThird party packet initiates network data request .
Please refer to @escook/request-miniprogram Official installation documentation 、 To configure 、 Use
Official documents :https://www.npmjs.com/package/@escook/request-miniprogram

According to the official process , We first install the corresponding package , Use command line tools cmd Go to the project root directory Initialize a package.json file
npm init -y

Copy the Import command of the official website
npm install @escook/request-miniprogram

Configure the entry file main.js
Import the corresponding package and mount it , And the definition Response interceptors and request responders
( stay uni-app In development , Try to do it all in the form of uni As a top-level object )
// Import network request package
import {
$http
} from '@escook/request-miniprogram'
// mount
uni.$http = $http
// Set the root path of the request address
$http.baseUrl = 'https://www.uinav.com'
// Request interceptor
$http.beforeRequest = function() {
uni.showLoading({
title: ' Data loading ...',
});
}
// Response interceptors
$http.afterRequest = function(){
uni.hideLoading()
}
3、 ... and 、 Carousel area
Request the data of the rotation chart
Implementation steps :
- stay data Defines an array of carousel charts in
- stay onLoad Method of calling round chart data in life cycle function
- stay methods Define the method of obtaining the data of the rotation chart in
Home page API
Get the rotation chart data of the home page
- Request path :https:// Request domain name /api/public/v1/home/swiperdata
- Request method :GET
- Request parameters
| Parameter name | Parameter description | remarks |
|---|---|---|
| nothing |
- Response parameter
| Parameter name | Parameter description | remarks |
|---|---|---|
| image_src | Picture path | |
| open_type | Navigation link type | |
| navigator_url | Navigation link path |
- Response data reference
{
"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 }
}
stay home.vue file in
<script>
export default {
data() {
return {
// Defining data
swiperList: []
};
},
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')
// Output data
console.log(res.data)
}
}
}
</script>
Printing successful ( Data acquisition success )
adopt meta Of status The attribute value determines whether Data acquired successfully
methods: {
async getSwiperList() {
// '/' The root directory is in main.js File configuration baseUrl
const res = await uni.$http.get('/api/public/v1/home/swiperdata')
// An error message will pop up when the call fails
if (res.data.meta.status != 200) {
uni.showToast({
title: " Data pull failed ", // Text display
'icon': "error", // Show Error Icon
"duration": 1500 // Set the dwell event to 1.5s duration - Continuous events
})
// Data to be called assignment
this.swiperList = res.data.message
}
}
}
Assignment successful 
Four 、 matters needing attention !:
The assignment here cannot be like Native applet call
this.setData({this.swiperList = res.data.message})Use , You can use... In appletsthis.dataUpdating data does not update the view andthsi.setData({})Data and views are updated synchronously ( The data rendering page will be reloaded ),But in uni-app It's not
thsi.setData({})Methodical , Usethis.dataDirect assignment . This is because in native applet development , Data nodes data Is defined as a dictionary , And in the uni-app Is to get data in the form of a function return value , At this point, the data can be directly assigned .
5、 ... and 、 Rendering the carousel UI structure
uswiper Quickly generate Carousel code block
- Use vue-for Dynamic looping chart array , Cyclic dynamic binding requires that the label attribute node be preceded by
:( The colon:yesv-bindAbbreviation , That is, dynamically binding data , It can be followed by variables or variable expressions , If there is no colon, it is a string , At this time, the loop will not display the effect
<!-- 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">
<view class="swiper-item">
<image :src="item.image_src"></image>
</view>
</swiper-item>
</swiper>
</view>
</template>
<!-- style -->
<style lang="scss">
swiper {
height: 333rpx;
.swiper-item,
image {
width: 100%;
height: 100%;
}
}
</style>
- effect :
Thanks for reading , Your praise and collection are the biggest motivation for me to create !
边栏推荐
- Hello Playwright:(7)模拟键盘和鼠标
- 让RDS(for MySQL)数据库的慢日志、审计日志跨空间转存OBS变得更加自动化
- ABP Framework 5.3.0 版本新增功能和变更说明
- NLog自定义Target之MQTT
- Kibana+elk cluster log processing
- 如何理解volatile
- Mybaits: interface proxy implementation Dao
- Docker 之MySQL 重启,提示Error response from daemon: driver failed programming external connectivity on **
- Mybaits:接口代理方式实现Dao
- The MySQL of docker restarts, prompting error response from daemon: driver failed programming external connectivity on**
猜你喜欢

关于#数据库#的问题,如何解决?

Application description of DAP fact table processing summary function

抢先报名丨新一代 HTAP 数据库如何在云上重塑?TiDB V6 线上发布会即将揭晓!

来厦门了!线上交流限额免费报名中

MySQL master-slave connection prompt of docker: communications link failure

【FPGA+PWM】基于FPGA的三相PWM整流器移相触发电路的设计与实现

It may be the most comprehensive Matplotlib visualization tutorial in the whole network

写给 Kubernetes 工程师的 mTLS 指南

可能是全网最全的Matplotlib可视化教程

Xshell 7 (SSH Remote Terminal tool) v7.0.0109 official Chinese Version (with file + installation tutorial)
随机推荐
同花顺软件是什么?手机开户安全么?
Application description of DAP fact table processing summary function
Seeing the big from the small: a simple example of domain modeling, understanding "domain driven".
MySQL instruction executes SQL file
Arrays Aslist uses bug
新手必会的静态站点生成器——Gridsome
QT notes qmap user defined key
Kibana+elk cluster log processing
短视频直播源码,EditText输入框的使用
【招聘】[北京中关村/远程][TensorBase][开源数据仓库]等一群人,做一件事
Xftp 7(FTP/SFTP客户端) V7.0.0107 官方中文免费正式版(附文件+安装教程)
缺失值处理
当线上线下的融合加速,当信息对接渠道的多样化,传统意义上的中心将没有必要
Quickly master asp Net authentication framework identity - login and logout
一文带你掌握Tcpdump命令的使用
Read Apache shardingsphere
UI自动化定位利器-xpath实战
Fluentd is easy to get started. Combined with the rainbow plug-in market, log collection is faster
Gridhome, a must-have static site generator for beginners
SaaS化应用开发指南
