Element UI 有个图片预览功能,即给图片加上preview-src-list属性,就可设置预览图数组。
<div class="demo-image__preview">
<el-image
style="width: 100px; height: 100px"
:src="url"
:preview-src-list="srcList">
</el-image>
</div>
<script>
export default {
data() {
return {
url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
srcList: [
'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg'
]
}
}
}
</script>
但其实这是两个功能,一个是图片展示功能,一个是图片预览功能
如果需求是点击按钮或者图片显示预览图,可能就无法满足,不过有网友发现了Elementui中的图片预览也是一个组件,并且可以单独使用:
<template>
<div>
<el-button @click="showViewer=true">预览</el-button>
<el-image-viewer
v-if="showViewer"
:on-close="()=>{showViewer=false}"
:url-list="imgList" />
</div>
</template>
<script>
export default {
name: 'Index',
components: {
'el-image-viewer':()=>import('element-ui/packages/image/src/image-viewer')
},
data() {
return {
showViewer: false,
imgList:['1.jpg','2.jpg']
}
}
</script>
表格里的按钮预览:
image.png
<el-table-column prop="headimgurl" label="生成图片" align="center">
<template slot-scope="{ row }">
<el-button type="text" @click="urtemp = [row.url];urlshow = true">预览</el-button>
<el-image-viewer
v-if="urlshow"
:on-close="()=>{urlshow = false}"
:url-list="urtemp" />
</template>
</el-table-column>
网友评论