vue实现‘换一批’功能
实现效果:从9个数里每次取5个数,取完了从头再取,
[1,2,3,4,5,6,7,8,9],第一次取[1,2,3,4,5],第二次取[6,7,8,9,1],第三次取[2,3,4,5,6],第四次取[7,8,9,1,2],,,,以此类推
<div class="flex-align" @click="change"> <span>换一批</span> </div> data () { return { qList: [], currentIndex: 0, num: 5, }; }, methods:{ // 换一批 change () { const batch = [] for (let i = 0; i < this.num; i++) { batch.push(this.qList[this.currentIndex]) this.currentIndex= (this.currentIndex + 1) % this.qList.length } console.log(batch) }, }, created () { this.$https("get", "/xxx/xxx", params) .then(res => { this.qList = res.data.data; this.change(); }) .catch(err => { }); },