我们在用 element UI
做项目时,当想点击文字或按钮来实现图片放大预览时可以通过以下代码实现
element
的 image-viewer
文件import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
let prevOverflow = '';
export default {
components: { ElImageViewer },
data() {
return {
showViewer:false,
imageUrl:['http://www.good1230.com/dist/server/images/adsense/1613693385.jpg'],
}
},
methods:{
clickHandler() {
// prevent body scroll
prevOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
this.showViewer = true;
},
closeViewer() {
document.body.style.overflow = prevOverflow;
this.showViewer = false;
}
}
};