效果
导入组件
import ElImageViewer from "element-ui/packages/image/src/image-viewer";
components:{ ElImageViewer },
模板使用组件
<el-image-viewer
v-if="isShowPics"
:on-close="closeViewer"
:url-list="srcList"
/>
定义两个变量
isShowPics:false,
srcList:[],
在v-html添加点击获取图片
<div v-html="newsForm.content" @click="getImg($event)" style="padding-left: 50px;padding-right: 50px;"></div>
两个点击事件,包含预览时滚动异常
closeViewer(){
this.isShowPics = false
this.srcList = []
move()
//取消滑动限制
function move(){
var mo=function(e){
e.preventDefault();
};
document.body.style.overflow='';//出现滚动条
document.removeEventListener("touchmove",mo,false);
}
},
getImg($event){
let currentSrc=$event.target.currentSrc
if (currentSrc){
this.srcList = [currentSrc]
this.isShowPics = true
stop()
}
//禁止滚动
function stop(){
var mo=function(e){
e.preventDefault();
};
document.body.style.overflow='hidden';
document.addEventListener("touchmove",mo,false);//禁止页面滑动
}
},