无需引用插件版
如果el-image-viewer组件在el-dialog里面,el-dialog的层级是优先的,因此我们需要属性z-index去更改el-image-viewer组件样式的层级
<template>
<div>
<el-button @click="onPreview">预览
</el-button>
<el-image
ref="preview"
class="hideImgDiv"
:src="url"
:preview-src-list="[url]"
z-index="9999"
></el-image>
</div>
</template>
<script>
export default {
name: 'Index',
data() {
return {
url:'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg'
}
},
methods: {
onPreview() {
this.$refs.preview.clickHandler();
},
}
</script>
<style scope="scss">
.hideImgDiv {
/deep/ .el-image__inner {
display: none;
}
}
</style>
element 图片预览插件版
需要考虑是否对项目里面element 引用版本升级
<template>
<div>
<el-button @click="onPreview">预览
</el-button>
<el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="[url]" />
</div>
</template>
<script>
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
export default {
name: 'Index',
components: { ElImageViewer },
data() {
return {
showViewer: false,
url:'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg'
}
},
methods: {
onPreview() {
this.showViewer = true
},
closeViewer() {
this.showViewer = false
}
}
</script>