当前位置:   article > 正文

element 表格上的图片做轮播图_element ui 表格 轮播图

element ui 表格 轮播图

表格里面嵌套图片,伴随着分页的加载,有时候想便捷的预览图片与相关信息,那么绑定键盘事件,由左右键来操作表格数据,弹框不消失!

在这里插入图片描述
在这里插入图片描述

首先要滤清思路每次操作的数据都是,接口上分页上的 pageSize数据,因此我们总体改变tableData,内部操作 tableData的内层 index值,由左右键来确定上下页的数据
父组件
 <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()   //请求表格数据的接口
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

子组件

<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>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173

如果最后数据回显正常,但是表格下面的分页页码不正确,可以采用.sync解决

//父组件上的分页
 <el-pagination
          background
          layout="total, prev, pager, next, jumper"
          :page-size="search.page_count"
          :total="total"
          :current-page.sync="num"   //可以添加.sync的方式
          @current-change="handleCurrentChange"
        />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这样问题基本就解决了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/251024
推荐阅读