v-html展示富文本数据,实现图片放大预览功能

HTML:

<!-- 富文本内容展示部分 -->
<div class="quillCon ql-editor" v-html="quillContent" @click="showImg($event)"></div>

<!-- 富文本中图片放大预览部分 --> <div class="previewImg" @click="imgShowHandler" v-show="imgShow"> <img :src="previewImg" alt=""> </div>

js:

<script>
export default {
  data () {
    return {
      imgShow:false,
      previewImg:'',//预览图片路径
    };
  },
  methods: {
      showImg(e){
         if (e.target.tagName == 'IMG') {
            this.previewImg = e.target.src
            this.imgShow = true
          }
      },
      imgShowHandler(){
         this.imgShow = false
      },
  },
}
</script>

 CSS:

.home .previewImg{
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background:#000000;
  position: fixed;
  top:0;
  left: 0;
  display: flex;
  align-items: center;
  img{
    width:100vw;
  }
}

 

posted @ 2022-01-27 15:02  小那  阅读(1816)  评论(0编辑  收藏  举报