今天做一个点击文字查看图片的功能,大体页面长这样子,点击查看显示对应的图片
引入el-image-viewer
,点击的文字时候设置图片预览组件显示并传入图片的地址
关键代码
html
<el-link v-if="scope.row.fileList.length > 0" type="primary" @click="handleClickImage(scope.row)" :underline="false">查看</el-link>
<el-image-viewer v-if="imageShow" :on-close="() => { imageShow = false; }" :url-list="imageList" />
javascript
components: {
'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer')
},
data() {
return {
imageShow: false,
imageList: []
};
},
methods: {
handleClickImage(e) {
this.imageShow = true
let urls = e.fileList.map(obj => obj.url);
this.imageList = urls;
},
}