当前位置:网站首页>小程序開發的部分功能
小程序開發的部分功能
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()
},
边栏推荐
- 网络安全-扫描与密码爆破2
- Some functions of applet development
- Force buckle 204 Count prime
- Introduction to kotlin collaboration
- 7-25 read numbers (loop switch)
- 网络安全-中间人攻击
- Network security - cracking system passwords
- Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
- How is the mask effect achieved in the LPL ban/pick selection stage?
- Steps to obtain SSL certificate private key private key file
猜你喜欢
[技术发展-23]:DSP在未来融合网络中的应用
Steps to obtain SSL certificate private key private key file
[principles of multithreading and high concurrency: 2. Solutions to cache consistency]
力扣 204. 计数质数
[QT] encapsulation of custom controls
Some functions of applet development
High-Resolution Network (篇一):原理刨析
View of MySQL
One of the C language practical projects is greedy snake
一比特苦逼程序員的找工作經曆
随机推荐
STM32 - GPIO input / output mode
[Appendix 6 Application of reflection] Application of reflection: dynamic agent
PS去除水印详解
Network security - cracking system passwords
网络安全-木马
[shutter] animation animation (animatedwidget animation use process | create animation controller | create animation | create animatedwidget animation component | animation operation)
数学知识:台阶-Nim游戏—博弈论
C language course information management system
[error record] navigator operation requested with a context that does not include a naviga
力扣 204. 计数质数
网络安全-ACL访问控制列表
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
Three core issues of concurrent programming - "deep understanding of high concurrent programming"
海量数据冷热分离方案与实践
Why is it not recommended to use BeanUtils in production?
Smart management of Green Cities: Digital twin underground integrated pipe gallery platform
网络安全-DNS欺骗与钓鱼网站
什么是调。调的故事
Mathematical knowledge: Nim game game theory
Common English Vocabulary