本文主要是介绍VUE:在VUE中实现效果“换一换“功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
实现效果:假如有10条数据,分组展示,默认在当前页面展示4个,点击换一批,从第5个开始继续展示,到最后一组,再重新返回到第一组
data() {return {qList: [],//处理后的listnewList: [],//截取第几组的开始参数timeStart: 0,//截取第几组的结束参数timeEnd: 1,//默认为0组group: 0,//一页展示list数量num: 3,//点击的次数clickNum: 0};},
<div class="flex-align" @click="change"><span>换一批</span></div>
// 换一批change() {if (this.qList.length > 4 && this.qList.length > this.num) {//点击的时候获取分为几组this.listlen();//每点击一次记录点击次数this.autoIncre();this.clear();this.renderR();}},// 计算数据的长度,共分为几组,如果不能整除则加1listlen() {var len = this.qList.length;this.group = len / this.num;if (len % this.num != 0) {this.group = parseInt(this.group) + 1;}},//计算将点击次数和开始截取的参数清空, 如果点击此时大于当前数据的组数,则重新开始计数。clear() {if (this.clickNum > this.group - 1) {this.timeStart = 0;this.timeEnd = 1;this.clickNum = 0;}},//每点击一次,记录次数autoIncre() {this.clickNum++;this.timeStart++;this.timeEnd++;},//截取当前每组的数据renderR() {this.newList = this.qList.slice(this.num * this.timeStart,this.num * this.timeEnd);console.log(this.newList);}},//获取总数据created() {let params = {keyword: ""};this.$https("get", "/xxx/xxx", params).then(res => {var data = res.data.data;this.qList = data;this.renderR();}).catch(err => {});}
转载于:https://blog.csdn.net/qinyongqaq/article/details/89703070?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&dist_request_id=1328769.106.16172655068895357&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
这篇关于VUE:在VUE中实现效果“换一换“功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!