国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Vue分頁器實現(xiàn)原理詳解

2024-05-06 15:37:18
字體:
供稿:網(wǎng)友

本文為大家講解了Vue分頁器實現(xiàn)原理,供大家參考,具體內(nèi)容如下

網(wǎng)上搜的分頁器大多是jQuery實現(xiàn)的,而且也不太完善,于是自己寫了個分頁器組件,以后再用也不慌,直接復(fù)制過去就ok,下面說說具體實現(xiàn)的代碼和原理吧。

新聞組件template:

<template> <div v-if="news"> <div v-for="(item, index) in newList" v-if="(index <= (newListPageIndex * 4)-1) && (index >= (newListPageIndex-1) * 4)" class="new-show-left"> <div class="new-img">  <img :src="item.img" alt=""/> </div> <div class="time">  <span>{{item.time}}</span> </div> <h1>{{item.title}}</h1> <p>{{item.content}}</p> </div> </div></template><script type="text/ecmascript-6"> import page from '@/components/page' import bus from '@/eventBus/eventBus' import {getNew} from '@/getData/getData' export default{ components: { page }, data () { return { newList: '', newList2: '', newListLength: '', newListPageIndex: '1', // 下標 next: false, previous: false, news: true, title: '' } }, created () { this.$nextTick(() => { this._init_list1() }) bus.$on('current-item', (ev) => { this.$nextTick(() => {  this.currentItem(ev) }) }) bus.$on('next-page', (ev) => { this.$nextTick(() => {  this.nextPage(ev) }) }) bus.$on('previous-page', (ev) => { this.$nextTick(() => {  this.previousPage(ev) }) }) }, methods: { _init_list1 () { getNew().then(res => {  this.newList = res.data.list1  let myObject = res.data.list1  this.newListLength = Object.keys(myObject).length  this.newListLength = Math.ceil((this.newListLength) / 6)  this.pageStyle() }) }, pageStyle () { if (this.newListPageIndex < this.newListLength) {  this.next = true  if (this.newListPageIndex > 1) {  this.previous = true  } else {  this.previous = false  } } else {  this.next = false  if (this.newListPageIndex > 1) {  this.previous = true  } else {  this.previous = false  } } }, currentItem (ev) { this.newListPageIndex = ev window.scrollTo(0, 500) this.pageStyle() }, nextPage () { if (this.newListPageIndex < this.newListLength) {  this.newListPageIndex ++  window.scrollTo(0, 500)  this.pageStyle() } }, previousPage () { if (this.newListPageIndex > 1) {  this.newListPageIndex --  window.scrollTo(0, 500)  this.pageStyle() } } } }</script>

分頁器組件template:

<template> <ul class="page"> <li>  <img @click="previousPage" :src="[(previous==true ? 'static/images/leftGo-black.png' : 'static/images/leftGo.png')]">  <span @click="previousPage" :class="[(previous==true ? 'black-color' : 'gray-color')]">上一頁</span> </li> <li >  <span @click="currentItem" v-for="(item, index) in listLength" :class="[(listPageIndex == index+1) ? 'gray-color':'black-color']">{{item}}</span> </li> <li>  <span @click="nextPage" :class="[(next == true ? 'black-color':'gray-color')]">下一頁</span>  <img @click="nextPage" :src="[(next==true ? 'static/images/rightGo.png' : 'static/images/rightGo-gray.png')]"> </li> </ul></template><script type="text/ecmascript-6"> import bus from '@/eventBus/eventBus' export default{ props: { listLength: '', listPageIndex: '', next: '', previous: '' }, created () {// console.log(this.next) }, methods: { currentItem (ev) { bus.$emit('current-item', ev.target.innerHTML) }, nextPage (ev) { bus.$emit('next-page', ev) }, previousPage (ev) { bus.$emit('previous-page', ev) } } }</script>            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 芮城县| 鸡东县| 卢氏县| 郴州市| 平顺县| 东山县| 顺义区| 万盛区| 桃源县| 缙云县| 衡阳县| 信宜市| 讷河市| 乌拉特中旗| 六枝特区| 玛多县| 汨罗市| 嘉兴市| 镇江市| 图木舒克市| 巴彦淖尔市| 小金县| 临洮县| 漳浦县| 蒙城县| 济南市| 思南县| 色达县| 偃师市| 松滋市| 营山县| 车险| 合肥市| 天津市| 巩义市| 乌拉特中旗| 钟山县| 长顺县| 左贡县| 香港| 娱乐|