当前位置:网站首页>小程序開發的部分功能
小程序開發的部分功能
2022-07-03 01:44:00 【Blizzard前端】
項目前的准備
關閉自動熱重載警告:詳情->本地設置->關閉“啟用代碼自動熱重載”
新建項目並梳理項目結構
配置導航欄效果
全局app.json->window
配置tabBar
在全局app.json中和window平級創建一個tabBar節點
實現輪播圖效果
接口地址
①獲取輪播圖數據列錶的接口
②在子頁面中定義獲取輪播圖數據的方法
③在onload中調用這個方法-通過this實例頁面一加載就調用
④通過setDate()將數據賦值data裏面的數組
data: {
//存放輪播圖數據的列錶
swiperList:[]
},
//獲取輪播圖數據的方法
getSwiperLsit()
{
wx.request({
url:'https://www.escook.cn/slides',
method:'GET',
success:(res)=>{
console.log(res);
this.setData({
swiperList:res.data
})
}
})
},
⑤渲染輪播圖的效果
<swiper indicator-dots circular>
<swiper-item wx:for="{
{swiperList}}" wx:key="id">
<image src="{
{item.image}}">
</image>
</swiper-item>
</swiper>
上拉觸底功能
步驟一-定義隨機獲取顏色的方法
data: {
colorList:[]
},
getColors(){
wx.request({
url: 'https://www.escook.cn/api/color',
method:'get',
success:({
data:res})=>{
console.log(res)
// 數據拼接
this.setData({
colorList:[...this.data.colorList,...res.data]
})
}
})
},
步驟二-在頁面加載時獲得初始數據
/** * 生命周期函數--監聽頁面加載 */
onLoad(options) {
this.getColors()
},
步驟三-渲染UI結構並美化頁面效果
<!--pages/contact/contact.wxml-->
<view wx:for="{
{colorList}}" wx:key="index" class="num-item" style="background-color: rgba({
{
item}});">{
{item}}</view>
頁面要足够大可以下拉刷新
步驟四-上拉觸底時獲取隨機顏色
//頁面上拉觸底事件的處理函數
onReachBottom:function(){
//調用獲取隨機顏色的方法
this.getColors()
}
上拉刷新,數據一次性獲取10條,由10條變成20條
步驟五-添加loading提示效果

getColors(){
//展示loading效果
wx.showLoading({
title: '數據加載中。。。',
})
wx.request({
url: 'https://www.escook.cn/api/color',
method:'get',
success:({
data:res})=>{
console.log(res)
// 數據拼接
this.setData({
colorList:[...this.data.colorList,...res.data]
})
},
//手動關閉數據加載
complete:()=>{
wx.hideLoading()
}
})
},
步驟六-對上拉觸底進行節流處理

data: {
colorList:[],
isloading:false
},
getColors(){
this.setData({
isloading:true
})
//展示loading效果
wx.showLoading({
title: '數據加載中。。。',
})
wx.request({
url: 'https://www.escook.cn/api/color',
method:'get',
success:({
data:res})=>{
console.log(res)
// 數據拼接
this.setData({
colorList:[...this.data.colorList,...res.data]
})
},
//手動關閉數據加載
complete:()=>{
wx.hideLoading()
this.setData({
isloading:false
})
}
})
},
onReachBottom() {
if(this.data.isloading) return
this.getColors()
},
边栏推荐
- 【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
- How is the mask effect achieved in the LPL ban/pick selection stage?
- 网络安全-扫描与密码爆破2
- Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
- 网络安全-防火墙
- 數學知識:臺階-Nim遊戲—博弈論
- 【数据挖掘】任务2:医学数据库MIMIC-III数据处理
- Introduction to kotlin collaboration
- 【数据挖掘】任务3:决策树分类
- Smart management of Green Cities: Digital twin underground integrated pipe gallery platform
猜你喜欢

Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm

【數據挖掘】任務6:DBSCAN聚類

"Jetpack - livedata parsing"

【面试题】1369- 什么时候不能使用箭头函数?

Summary of interval knowledge

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr

How is the mask effect achieved in the LPL ban/pick selection stage?

How is the mask effect achieved in the LPL ban/pick selection stage?
![[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array](/img/2a/98400b0d0b5eda1e52abae30746f2b.jpg)
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array

Pytest learning notes (12) -allure feature · @allure Step () and allure attach
随机推荐
Wireshark data analysis and forensics a.pacapng
[data mining] task 3: decision tree classification
[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)
Related concepts of GDB in embedded system
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
【數據挖掘】任務6:DBSCAN聚類
Network security - vulnerabilities and Trojans
View of MySQL
网络安全-漏洞与木马
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
Work experience of a hard pressed programmer
网络安全-防火墙
Network security - Information Collection
【数据挖掘】任务6:DBSCAN聚类
网络安全-浅谈安全威胁
Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
海量数据冷热分离方案与实践
Function definition and call, this, strict mode, higher-order function, closure, recursion
什么是调。调的故事
How is the mask effect achieved in the LPL ban/pick selection stage?