当前位置:网站首页>小程序開發的部分功能
小程序開發的部分功能
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()
},
边栏推荐
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- [机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
- [technology development-23]: application of DSP in future converged networks
- 网络安全-ACL访问控制列表
- SSL flood attack of DDoS attack
- [QT] encapsulation of custom controls
- [data mining] task 4:20newsgroups clustering
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- Network security ACL access control list
- 【QT】自定义控件的封装
猜你喜欢

STM32 - introduction of external interrupts exti and NVIC
![[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)](/img/fd/d862412db43a641537fd67f7910741.jpg)
[error record] an error is reported in the fluent interface (no mediaquery widget ancestor found. | scaffold widgets require a mediaquery)

Main features of transport layer TCP and TCP connection

QTableWidget懒加载剩内存,不卡!

High resolution network (Part 1): Principle Analysis

Qtablewidget lazy load remaining memory, no card!
![[interview question] 1369 when can't I use arrow function?](/img/7f/84bba39965b4116f20b1cf8211f70a.png)
[interview question] 1369 when can't I use arrow function?

【数据挖掘】任务6:DBSCAN聚类

SSL flood attack of DDoS attack

Tâche 6: regroupement DBSCAN
随机推荐
2022-02-15 reading the meta module inspiration of the influxdb cluster
网络安全-扫描与密码爆破2
Network security - scanning and password explosion 2
Network security - man in the middle attack
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
Main features of transport layer TCP and TCP connection
Virtual list
Force buckle 204 Count prime
[untitled]
Vant implements a simple login registration module and a personal user center
[shutter] animation animation (basic process of shutter animation | create animation controller | create animation | set value listener | set state listener | use animation values in layout | animatio
网络安全-扫描
What is tone. Diao's story
网络安全-信息收集
Wireshark data analysis and forensics a.pacapng
STM32 - Application of external interrupt induction lamp
Qtablewidget lazy load remaining memory, no card!
Why can't the start method be called repeatedly? But the run method can?
word插入公式/endnote
C application interface development foundation - form control (4) - selection control