官方给的示例需要用el-image
<div class="demo-image__preview"> <el-image style=" 100px; height: 100px" :src="url" :preview-src-list="srcList"> </el-image> </div>
但往往业务中可能是一个button 按钮 需要调previewSrcList
解决办法是需要调element组件包中的image-viewer.vue
<el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="srcList" /> <el-button @click="onPreview" type="primary">查看图片</el-button>
<script> import ElImageViewer from 'element-ui/packages/image/src/image-viewer' import HomeHeader from '../header/Header' import FooterView from '../footer/FooterView' import Condition from './components/Condition' import Tumor from './components/Tumor' import { getTumorSearchData } from '@/axios/api.js' import { Message } from 'element-ui'; export default { name:'TumorSearch', components:{ HomeHeader, FooterView, Condition, Tumor, ElImageViewer }, data(){ return{ showViewer: false, firstTumors:[], tumor:'tumor', url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', srcList: [ 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', 'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg', 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg' ] } }, methods:{ onPreview() { this.showViewer = true }, closeViewer() { this.showViewer = false }, loadimg(){ console.log(1); }, async getTumor(){ try{ const res = await getTumorSearchData(); const data = res.data; if(data.error_code == 0){ this.firstTumors = data.reason.tumors1; } }catch(err){ console.log(err) } } }, mounted(){ this.getTumor(); } } </script>
需要给 image-viewer 传递
urlList ,
onClose