当前位置:网站首页>小程序開發的部分功能
小程序開發的部分功能
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()
},
边栏推荐
- GDB 在嵌入式中的相关概念
- 电信客户流失预测挑战赛
- 音程的知识的总结
- [Appendix 6 Application of reflection] Application of reflection: dynamic agent
- What is tone. Diao's story
- What operations need attention in the spot gold investment market?
- 【數據挖掘】任務6:DBSCAN聚類
- 网络安全-信息收集
- Using tensorboard to visualize the model, data and training process
- [error record] navigator operation requested with a context that does not include a naviga
猜你喜欢
网络安全-漏洞与木马
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
7-25 read numbers (loop switch)
C application interface development foundation - form control (2) - MDI form
海量数据冷热分离方案与实践
【数据挖掘】任务2:医学数据库MIMIC-III数据处理
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
Smart management of Green Cities: Digital twin underground integrated pipe gallery platform
【面试题】1369- 什么时候不能使用箭头函数?
Learn the five skills you need to master in cloud computing application development
随机推荐
【數據挖掘】任務6:DBSCAN聚類
【数据挖掘】任务1:距离计算
uniapp组件-uni-notice-bar通告栏
PS remove watermark details
Mathematical Knowledge: Steps - Nim Games - Game Theory
String splicing function of MySQL
网络安全-扫描
电信客户流失预测挑战赛
【数据挖掘】任务4:20Newsgroups聚类
STM32 - vibration sensor control relay on
Wordinsert formula /endnote
C语言课程信息管理系统
[error record] navigator operation requested with a context that does not include a naviga
Force buckle 204 Count prime
How is the mask effect achieved in the LPL ban/pick selection stage?
C language course information management system
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
Network security - scanning and password explosion 2
Installation and use of serial port packet capturing / cutting tool
High-Resolution Network (篇一):原理刨析