当前位置:网站首页>[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 !
边栏推荐
- Team management | how to improve the thinking skills of technical leaders?
- Hello playwright: (7) simulate keyboard and mouse
- 网络智能运维助力运维效率提升
- QT notes qmap user defined key
- Arrays Aslist uses bug
- 写给 Kubernetes 工程师的 mTLS 指南
- 当线上线下的融合加速,当信息对接渠道的多样化,传统意义上的中心将没有必要
- 一文带你掌握Tcpdump命令的使用
- Come to Xiamen! Online communication quota free registration
- The principle of locality in big talk
猜你喜欢

DAP事实表加工汇总功能应用说明

Missing value handling

Xftp 7 (ftp/sftp client) v7.0.0107 official Chinese free official version (with file + installation tutorial)

Docker之MySQL主从连接提示:Communications link failure

Quartus Prime 18.0软件安装包和安装教程

UI自动化定位利器-xpath实战

MTLs guidelines for kubernetes engineers

云端极简部署Svelte3聊天室

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

##Kibana+ELK集群日志处理
随机推荐
.NET 发布和支持计划介绍
MYSQL_ ERRNO : 1292 Truncated incorrect date value At add_ num :1
Service or mapper cannot be injected into a multithread
以小见大:一个领域建模的简单示例,理解“领域驱动”。
Short video live broadcast source code, use of EditText input box
【FPGA+PWM】基于FPGA的三相PWM整流器移相触发电路的设计与实现
试用了多款报表工具,终于找到了基于.Net 6开发的一个了
Heartless sword in Chinese
Which platform is safer to buy stocks on?
让RDS(for MySQL)数据库的慢日志、审计日志跨空间转存OBS变得更加自动化
Hello playwright: (7) simulate keyboard and mouse
启牛学堂给的中信建投证券账户是不是真的?开户安全吗
诺亚财富拟登陆港交所:第一季度业绩大幅下滑,曾踩雷“承兴案”
WPF achieves star effect
Qt Notes - qmap Custom key
你管这破玩意儿叫高可用?
Defaultifempty for C # -linq source code analysis
MTLs guidelines for kubernetes engineers
Tried several report tools, and finally found a report based on Net 6
. NETCORE enables image scaling and cropping - based on imagesharp
