赞
踩
<el-dialog title="轮播" :visible.sync="dialogVisible3" :before-close="handleClose3" :close-on-click-modal="false" :destroy-on-close="true" width="1040px" custom-class="dialog3" > <div class="diavie" v-if="dialogVisible3"> <!-- 轮播组件 --> <Corridor ref="corridorComponent" :total="total" :num="num" :data-arr="tableData" @changeNum="changePageNum" ></Corridor> </div> </el-dialog> data(){ return { tableData:[], num:1 } } methods:{ changePageNum(type) { //从子组件传回的方法,取决于 上/下一(张) 或者 上/下(页) if (type.val === "next") { this.num++; this.handleCurrentChange(this.num); } else if (type.val === "prev") { if (this.num >= 2) { //规避每次减到第二页时,将不再执行,防止 页码到 -1 页 this.num--; } this.handleCurrentChange(this.num); } }, handleCurrentChange(val) { this.page.pageNo =val this.check() //请求表格数据的接口 } }
<template> <div class="corridor"> <div class="inspect_titlle"> 预览页数据 <b>{{ num }}/{{ Math.ceil(total / 20) }}</b> 当前为第<strong>{{ index + 1 }}</strong >条 </div> <div class="img" v-if="dataList[index]"> //这块内容不需要看,直接放置自己的carousel 即可 <SignedImage :style="{ width: '1000px', height: '650px' }" :image="dataList[index].capture_url" :region="dataList[index].region" /> </div> </div> <div class="btns"> <el-button @click="prevData" class="btn prev" :disabled="leftTrue" icon="el-icon-arrow-left" circle ></el-button> <el-button @click="nextData" :disabled="rightTrue" class="btn next" icon="el-icon-arrow-right" circle ></el-button> </div> </div> </template> <script> import SignedImage from "@/components/signedImage"; export default { data() { return { // 要显示的当前图片的索引 index: 0, }; }, props: { dataArr: { type: Array, default: () => [], }, total: { type: Number, }, num: { type: Number, }, }, computed: { dataList() { return this.dataArr; }, leftTrue() { return this.index <= 0 && this.num === 1; }, rightTrue() { return ( this.index >= this.dataList.length - 1 && Math.ceil(this.total / 20) === this.num ); }, }, mounted() { // 主页添加键盘事件,注意,不能直接在焦点事件上添加回车 window.addEventListener("keyup", this.handleKeyUp); }, watch: { dataList: { handler() { this.index = 0; }, deep: true, }, }, methods: { handleKeyUp(e) { let that = this; if (e.code == "ArrowLeft" && this.leftTrue !== true) { that.prevData(); } if (e.code == "ArrowRight" && this.rightTrue !== true) { that.nextData(); } }, //下一张及下一页的判断 nextData() { let oldIndex = this.index; let n = oldIndex + 1; if (n === this.dataList.length - 1) { this.$message("已经是最后一张了"); } else if (n > this.dataList.length - 1) { this.$message.success("请求下一页"); let type = { val: "next" }; this.$emit("changeNum", type); n = 0; } this.index = n; }, //上一张及上一页的判断 prevData() { let n = this.index - 1; if (n === 0) { this.$message("已经是第一张了"); } else if (n < 0) { let type = { val: "prev" }; this.$emit("changeNum", type); n = this.dataList.length - 1; } this.index = n; }, }, components: { SignedImage, }, beforeDestroy() { //关闭的时候必须销毁,不然下一次打开会影响下一次的结果值 window.removeEventListener("keyup", this.handleKeyUp); }, }; </script> <style lang="scss" scoped> .corridor { width: 100%; height: 700px; color: deeppink; position: relative; .inspect_titlle { font-size: 18px; padding: 5px 0; background: #eee; color: #000; b { color: #f00; } strong { color: rgb(60, 86, 233); } } .img { margin-top: 10px; max-height: 650px; img { width: 100%; } } .btns { .btn { position: absolute; z-index: 9; top: 45%; } .next { right: 0; } } } </style>
//父组件上的分页
<el-pagination
background
layout="total, prev, pager, next, jumper"
:page-size="search.page_count"
:total="total"
:current-page.sync="num" //可以添加.sync的方式
@current-change="handleCurrentChange"
/>
这样问题基本就解决了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。