網站首頁 Vue 正文
本文實例為大家分享了Vue實現點擊按鈕進行上下頁切換的具體代碼,供大家參考,具體內容如下
案例效果:
完整代碼如下:?
<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, //總頁數 ? ? ? ? selected: 0 //已選擇的頁,默認開始時為第一頁 ? ? ? ? //因為是與下標index作比較,所以要從0開始;0代表第一頁,依次類推 ? ? ? } ? ? }, ? ? methods: { ? ? ? //上一頁 ? ? ? prePage() { ? ? ? ? //如果已經在第一頁,點擊按鈕頁碼不變并彈出提示 ? ? ? ? if (this.selected == 0) { ? ? ? ? ? this.selected; ? ? ? ? ? alert('已經是第一頁!'); ? ? ? ? ? //否則當前頁數-1 ? ? ? ? } else { ? ? ? ? ? this.selected = this.selected - 1; ? ? ? ? } ? ? ? }, ? ? ? //下一頁 ? ? ? nextPage() { ? ? ? ? //如果已經在最后一頁,點擊按鈕頁碼不變并彈出提示 ? ? ? ? if (this.selected == this.pageCount - 1) { ? ? ? ? ? this.selected; ? ? ? ? ? alert('已是最后一頁!'); ? ? ? ? } else { ? ? ? ? ? //否則當前頁數+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; ? ? ? /*未選中時的頁碼樣式*/ ? ? 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>
原文鏈接:https://majinjian.blog.csdn.net/article/details/121904365
相關推薦
- 2022-09-03 Python?Opencv使用ann神經網絡識別手寫數字功能_python
- 2022-12-25 Redis中AOF與RDB持久化策略深入分析_Redis
- 2022-06-10 FreeRTOS使用任務通知實現命令行解釋器_操作系統
- 2023-06-17 C或C++報錯:ld?returned?1?exit?status報錯的原因及解決方法_C 語言
- 2022-05-18 React?Hook之使用Effect?Hook的方法_React
- 2022-08-12 Windows?Server?修改遠程桌面端口的實現_win服務器
- 2023-02-09 C++命名空間?缺省參數?const總結?引用總結?內聯函數?auto關鍵字詳解_C 語言
- 2022-04-12 C++制作簡單的計算器功能_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支