element-plus之element-image-viewer的使用

想通过按钮直接触发图片预览,而不是通过点击图片预览,搜索后发现element的隐藏组件:element-image-viewer。

 template:

<el-table-column  label="图片上传" min-width="10%">
        <template #default="scope">
          <el-button  @click="checkImg(scope.row.imageList)"  :type="scope.row.imageList.length>0?'primary':'info'">{{scope.row.imageList.length>0?'查看':'未上传图片'}}</el-button>
        </template>
</el-table-column>


<el-image-viewer @close="closeImgViewer" :url-list="imageList" v-if="showImageViewer"/>

script:

checkImg(imgList){
      if(imgList.length>0){
        this.showImageViewer=true,
        this.imageList=imgList
      }else{
        this.$alert('当前记录未上传图片', '提示', {
          confirmButtonText: '确定',
        });
      }
    },
 closeImgViewer(){
      console.log(99999)
      this.showImageViewer=false
 }

值得注意的是:由于官方文档没提这个组件,我在别的博客里看到的给组件绑定关闭事件用的都是:on-close="close",我这样绑定是触发不了关闭事件的,找了好大一圈都没有找到解决方法,最终去官方文档image组件下看了看,尝试着改成了@close="close"没想到居然成功了。。。。。。。。。。。。

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值