当前位置:网站首页>小程序开发的部分功能
小程序开发的部分功能
2022-07-03 01:17: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()
},
边栏推荐
- Using tensorboard to visualize the model, data and training process
- How is the mask effect achieved in the LPL ban/pick selection stage?
- 串口抓包/截断工具的安装及使用详解
- [data mining] task 3: decision tree classification
- The meaning of wildcard, patsubst and notdir in makefile
- 网络安全-NAT网络地址转换
- Button wizard play strange learning - automatic return to the city route judgment
- Three core issues of concurrent programming - "deep understanding of high concurrent programming"
- Vant 实现简单的登录注册模块以及个人用户中心
- [shutter] animation animation (animatedbuilder animation use process | create animation controller | create animation | create components for animation | associate animation with components | animatio
猜你喜欢

Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man
![[interview question] 1369 when can't I use arrow function?](/img/7f/84bba39965b4116f20b1cf8211f70a.png)
[interview question] 1369 when can't I use arrow function?

Introduction to flask tutorial

【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
![[understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait](/img/c6/9aee30cb935b203c7c62b12c822085.jpg)
[understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait

Vant implements a simple login registration module and a personal user center

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

After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9

STM32 - switch of relay control lamp
![[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core](/img/fb/c371ffaa9614c6f2fd581ba89eb2ab.png)
[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core
随机推荐
MySQL - database query - condition query
Expérience de recherche d'emploi d'un programmeur difficile
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
Uniapp component -uni notice bar notice bar
[technology development-23]: application of DSP in future converged networks
Leetcode skimming questions_ Sum of two numbers II - enter an ordered array
Installation and use of serial port packet capturing / cutting tool
[androd] module dependency replacement of gradle's usage skills
C application interface development foundation - form control (2) - MDI form
力扣 204. 计数质数
tail -f 、tail -F、tailf的区别
[data mining] task 2: mimic-iii data processing of medical database
Dotconnect for PostgreSQL data provider
Qtablewidget lazy load remaining memory, no card!
[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core
Vant implements a simple login registration module and a personal user center
Common English Vocabulary
What operations need attention in the spot gold investment market?
Steps to obtain SSL certificate private key private key file
Test shift right: Elk practice of online quality monitoring