el-image 循环展示多张图片,点击放大,点击空白处关闭遮罩层。

 <el-image v-for="(img,index) in ImagesrcList" 
 :src="img"
 :preview-src-list="getImgList(index)"
  @click="handleClickItem">
  el-image>
  data() {
    return {
      ImagesrcList: [
        'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
        'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg'
      ],
	}
  },
 
   methods: {
	//循环展示图片
    getImgList(index) {
      let arr = []
      let i = 0
      for (i; i < this.ImagesrcList.length; i++) {
        arr.push(this.ImagesrcList[i + index])
        if (i + index >= this.ImagesrcList.length - 1) {
          index = 0 - (i + 1)
        }
      }
      return arr
    },
     // 关闭el-image遮罩层
    handleClickItem() {
      this.$nextTick(() => {
        // 获取遮罩层dom
        let domImageMask = document.querySelector('.el-image-viewer__mask')
        if (!domImageMask) {
          return
        }
        domImageMask.addEventListener('click', () => {
          // 点击遮罩层时调用关闭按钮的 click 事件
          document.querySelector('.el-image-viewer__close').click()
        })
      })
    }
  }

你可能感兴趣的:(javascript,前端,vue.js)