当前位置:网站首页>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 !
边栏推荐
- Some configuration details about servlet initial development
- 【npm】解决使用npm安装TypeORM的报错问题
- Five cheapest wildcard SSL certificate brands
- Lua 基础知识
- Raii memory management
- Jupyter notebook displays a collection of K-line graphs
- Summary of knowledge points about eigenvalues and eigenvectors of matrices in Chapter 5 of Linear Algebra (Jeff's self perception)
- 选购通配符SSL证书注意事项
- How to prevent phishing emails? S/mime mail certificate
- Xunwei enzhipu ITop - imx6 Development Platform
猜你喜欢

【postgres】postgres 数据库迁移

五个最便宜的通配符SSL证书品牌

Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery

Entering Jiangsu writers and poets carmine Jasmine World Book Day

Insert sort directly

走进江苏作家诗人胭脂茉莉|世界读书日

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

Jupyter notebook显示k线图集合

主流CA吊销俄罗斯数字证书启示:升级国密算法SSL证书,助力我国网络安全自主可控

SSL证书七大常见错误及解决方法
随机推荐
NPDP产品经理国际认证考试报名有什么要求?
迅为恩智浦iTOP-IMX6开发平台
Ffmpeg source code
Global and Chinese market of ERP software for garment and textile industries 2022-2028: Research Report on technology, participants, trends, market size and share
Quick sort
Redis+AOP怎么自定义注解实现限流
2. < tag dynamic programming and 0-1 knapsack problem > lt.416 Split equal sum subset + lt.1049 Weight of the last stone II
What about punctuation in the first column of unity text
并发请求下如何防重复提交
Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery
Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification
Welfare lottery | what are the highlights of open source enterprise monitoring zabbix6.0
What is certificate transparency CT? How to query CT logs certificate logs?
Raki's notes on reading paper: neighborhood matching network for entity alignment
Seven common errors of SSL certificate and their solutions
Pytorch学习(二)
IBM WebSphere channel connectivity setup and testing
在php中字符串的概念是什么
Heap sort
IBM websphere通道联通搭建和测试