Vue實(shí)現(xiàn)點(diǎn)擊按鈕進(jìn)行上下頁切換
更新時(shí)間:2022年01月25日 09:12:07 作者:前端小馬
這篇文章主要介紹了Vue實(shí)現(xiàn)點(diǎn)擊按鈕進(jìn)行上下頁的切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)點(diǎn)擊按鈕進(jìn)行上下頁切換的具體代碼,供大家參考,具體內(nèi)容如下
案例效果:
完整代碼如下:
<template> ? <div id="page"> ? ? <button class="btn" @click="prePage()">上一頁</button> ? ? <ul> ? ? ? <li :class="selected == index ?'page1':'page'" v-for="(item,index) of pageCount" :key="index">{{item}}</li> ? ? </ul> ? ? <button class="btn" @click="nextPage()">下一頁</button> ? </div> </template> ? <script> ? export default { ? ? data() { ? ? ? return { ? ? ? ? pageCount: 10, //總頁數(shù) ? ? ? ? selected: 0 //已選擇的頁,默認(rèn)開始時(shí)為第一頁 ? ? ? ? //因?yàn)槭桥c下標(biāo)index作比較,所以要從0開始;0代表第一頁,依次類推 ? ? ? } ? ? }, ? ? methods: { ? ? ? //上一頁 ? ? ? prePage() { ? ? ? ? //如果已經(jīng)在第一頁,點(diǎn)擊按鈕頁碼不變并彈出提示 ? ? ? ? if (this.selected == 0) { ? ? ? ? ? this.selected; ? ? ? ? ? alert('已經(jīng)是第一頁!'); ? ? ? ? ? //否則當(dāng)前頁數(shù)-1 ? ? ? ? } else { ? ? ? ? ? this.selected = this.selected - 1; ? ? ? ? } ? ? ? }, ? ? ? //下一頁 ? ? ? nextPage() { ? ? ? ? //如果已經(jīng)在最后一頁,點(diǎn)擊按鈕頁碼不變并彈出提示 ? ? ? ? if (this.selected == this.pageCount - 1) { ? ? ? ? ? this.selected; ? ? ? ? ? alert('已是最后一頁!'); ? ? ? ? } else { ? ? ? ? ? //否則當(dāng)前頁數(shù)+1 ? ? ? ? ? this.selected = this.selected + 1; ? ? ? ? } ? ? ? } ? ? } ? } </script> ? <style scoped lang="less"> ? * { ? ? font-size: 14px; ? ? font-weight: normal; ? } ? ? #page { ? ? display: flex; ? ? width: 80%; ? ? margin: auto; ? ? ? .btn { ? ? ? width: 70px; ? ? ? height: 35px; ? ? ? color: white; ? ? ? font-weight: bold; ? ? ? border: 0; ? ? ? margin: 0 5px; ? ? } ? ? ? .btn:hover { ? ? ? cursor: pointer; ? ? } ? ? ? .btn:active { ? ? ? background-color: #787878; ? ? } ? } ? ? ul { ? ? list-style: none; ? ? ? /*未選中時(shí)的頁碼樣式*/ ? ? li, .page { ? ? ? float: left; ? ? ? width: 35px; ? ? ? height: 35px; ? ? ? text-align: center; ? ? ? line-height: 35px; ? ? ? border: 1px solid lightskyblue; ? ? ? color: lightskyblue; ? ? ? margin: 0 3px; ? ? } ? ? ? /*選中后的頁碼樣式*/ ? ? .page1 { ? ? ? background-color: lightskyblue; ? ? ? color: white; ? ? } ? } </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
el-form表單el-form-item label不換行問題及解決
這篇文章主要介紹了el-form表單el-form-item label不換行問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10詳解如何使用vue和electron開發(fā)一個(gè)桌面應(yīng)用
這篇文章主要為大家介紹了詳解如何使用vue和electron開發(fā)一個(gè)桌面應(yīng)用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03Vue build過程取消console debugger控制臺(tái)信息輸出方法詳解
這篇文章主要為大家介紹了Vue build過程取消console debugger控制臺(tái)信息輸出方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09