当前位置:网站首页>How to use vant to realize data paging and drop-down loading
How to use vant to realize data paging and drop-down loading
2022-06-30 02:46:00 【Yisu cloud】
How do you use it? Vant Realize data paging and drop-down loading
This article mainly explains “ How do you use it? Vant Realize data paging and drop-down loading ”, Interested friends might as well come and have a look . The method introduced in this paper is simple and fast , Practical . Now let Xiaobian take you to learn “ How do you use it? Vant Realize data paging and drop-down loading ” Well !
Vant-ui Of van-list Realize data paging loading
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>vant Data paging , Pull down load </title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/lib/index.css" rel="external nofollow" /></head><style></style><body> <div id='app'> <van-list class="lazy" v-model="loading" :finished="finished" finished-text=" There is no more " @load="onLoad" :immediate-check="false"> <div v-for="(item,index) in list" :key="index">{{item}}</div> </van-list> </div></body><script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script><script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/vant.min.js"></script><script> var Vue = new Vue({ el: '#app', data: { list: [], page: 1, loading: false, finished: false, num: 0 }, created() { this.getList() }, mounted() { }, methods: { // Request public method ajax(url, params, cb) { $.ajax({ type: 'post', url: url, data: params, dataType: "json", success: function (response) { cb(response) } }); }, onLoad() { this.getList() }, getList() { let that = this that.ajax('url', { kay: 'value' }, function (res) { if (res.errcode != 0) { that.$toast(res.msg) return false } if (that.page == 1) { that.list = res.data.list } else { that.list = that.list.concat(res.data.list) } that.loading = false; that.page++ // The data returned from the last request is null or less than 10 strip , No more requests ,finished = true // Change according to business needs if (res.data.list.length == 0 || res.data.list == null || res.data.list.length < 10) { that.finished = true return } }) } } })</script></html>
There are three main attributes


Be careful :
v-modelEach time the data is loaded, it should be set to falsefinishedSet as false Pull down loading will no longer be triggered afterimmediate-checkSet as false after , Every time you enter the page, it will not trigger load Method , Prevent the entry page from loading more than once

vant Pull up to load more , The drop-down refresh
1.html
<van-pull-refresh v-model="isLoading" @refresh="onRefresh"> <van-list v-model="loading" :finished="finished" :immediate-check="false" finished-text=" No more " @load="onLoad" > </van-list> </van-pull-refresh>
2.js
return { isLoading: false, loading: false, page: 1, limit: 10, finished: false, total: 0, // The total number of data List: [], } getHistory() { const historyData = { page: this.page, limit: this.limit } return new Promise((resolve, reject) => { getHistory(historyData) .then(res => { if (res.code === 0) { console.log(res, ' Historical record ') this.total = res.data.total this.finished = !res.data.hasNext if (res.data.list && res.data.list.length > 0) { const tempList = res.data.list // console.log(this.page) if (this.page > 1) { this.list = this.list.concat(tempList) } else { this.list = tempList // First load } this.page += 1 } else { this.list = [] } this.loading = false resolve() } }) .catch(error => { reject(error) }) }) }, onLoad() { this.getHistory() }, onRefresh() { this.page = 1 setTimeout(() => { this.getHistory() Toast(' Refresh successful ') this.isLoading = false }, 1000) },Here we are , I'm sure you're right “ How do you use it? Vant Realize data paging and drop-down loading ” Have a deeper understanding of , You might as well put it into practice ! This is the Yisu cloud website , For more relevant contents, you can enter the relevant channels for inquiry , Pay attention to our , Continue to learn !
边栏推荐
- 重看《Redis设计与实现》后记录几个要点
- Two methods of SSL certificate format conversion
- Cmake tutorial series -02- generating binaries using cmake code
- Unity timeline data binding
- Unity TimeLine 数据绑定
- What about punctuation in the first column of unity text
- 福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点
- 怎么利用Redis实现点赞功能
- Digicert、Sectigo、Globalsign代码签名证书的区别
- How to prevent duplicate submission under concurrent requests
猜你喜欢

什么是自签名证书?自签名SSL证书的优缺点?

DigiCert Smart Seal是什么?

Shell Sort

论文回顾:Playful Palette: An Interactive Parametric Color Mixer for Artists

A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022

Pytoch learning (II)

重看《Redis设计与实现》后记录几个要点

Steam elements hidden in science and Technology Education

Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)

Série de tutoriels cmake - 02 - génération de binaires à l'aide du Code cmake
随机推荐
模板参数包和函数参数包
Cmake tutorial series-03-dependency management
Implementation of Sanzi chess with C language
[on] [DSTG] dynamic spatiotemporalgraph revolutionary neural networks for traffic data impact
Insert sort directly
002 color classification
Azure 开发者新闻快讯丨开发者6月大事记一览
RAII内存管理
Intel-Hex , Motorola S-Record 格式详细解析
如何在 JupyterLab 中把 ipykernel 切换到不同的 conda 虚拟环境?
Several key points recorded after reviewing redis design and Implementation
Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery
C语言 pivot_root的Invalid argument错误解决方案
重看《Redis设计与实现》后记录几个要点
LeetCode 3. 无重复字符的最长子串
What should academic presentation /ppt do?
Network neuroscience——网络神经科学综述
三层交换机和二层交换机区别是什么
福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点
Detailed explanation of minimum stack