Vue實(shí)現(xiàn)點(diǎn)擊按鈕進(jìn)行上下頁切換
本文實(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>以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue全局方法plugins/utils的實(shí)現(xiàn)示例
很多時(shí)候我們會(huì)在全局調(diào)用一些方法,本文主要介紹了vue全局方法plugins/utils的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07
element?ui組件中element.style怎么改詳解
element.style是一種內(nèi)聯(lián)樣式,一般都是代碼里寫死的,下面這篇文章主要給大家介紹了關(guān)于element?ui組件中element.style怎么改的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06
laravel-admin 與 vue 結(jié)合使用實(shí)例代碼詳解
由于 Laravel-admin 采用的是 pjax 的方式刷新頁面,意味著很多頁面刷新的操作,這篇文章主要介紹了laravel-admin 與 vue 結(jié)合使用,需要的朋友可以參考下2019-06-06
Vue報(bào)錯(cuò)ERR_OSSL_EVP_UNSUPPORTED解決方法
Vue項(xiàng)目啟動(dòng)時(shí)報(bào)錯(cuò)ERR_OSSL_EVP_UNSUPPORTED,本文主要介紹了Vue報(bào)錯(cuò)ERR_OSSL_EVP_UNSUPPORTED解決方法,具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08
Vue實(shí)現(xiàn)動(dòng)態(tài)顯示表單項(xiàng)填寫進(jìn)度功能
這篇文章主要介紹了Vue實(shí)現(xiàn)動(dòng)態(tài)顯示表單項(xiàng)填寫進(jìn)度功能,此功能可以幫助用戶了解表單填寫的進(jìn)度和當(dāng)前狀態(tài),提高用戶體驗(yàn),通常實(shí)現(xiàn)的方式是在表單中添加進(jìn)度條,根據(jù)用戶填寫狀態(tài)動(dòng)態(tài)更新進(jìn)度條,感興趣的同學(xué)可以參考下文2023-05-05
vue-cli項(xiàng)目代理proxyTable配置exclude的方法
今天小編就為大家分享一篇vue-cli項(xiàng)目代理proxyTable配置exclude的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09
vue實(shí)現(xiàn)日歷表格(element-ui)
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)日歷表格(element-ui),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09

