作者 RuoYi

预览组件支持多图显示

1 <template> 1 <template>
2 - <el-image :src="`${realSrc}`" fit="cover" :style="`width:${realWidth};height:${realHeight};`" :preview-src-list="[`${realSrc}`]"> 2 + <el-image
  3 + :src="`${realSrc}`"
  4 + fit="cover"
  5 + :style="`width:${realWidth};height:${realHeight};`"
  6 + :preview-src-list="realSrcList"
  7 + >
3 <div slot="error" class="image-slot"> 8 <div slot="error" class="image-slot">
4 <i class="el-icon-picture-outline"></i> 9 <i class="el-icon-picture-outline"></i>
5 </div> 10 </div>
@@ -7,10 +12,10 @@ @@ -7,10 +12,10 @@
7 </template> 12 </template>
8 13
9 <script> 14 <script>
10 -import { isExternal } from '@/utils/validate' 15 +import { isExternal } from "@/utils/validate";
11 16
12 export default { 17 export default {
13 - name: 'ImagePreview', 18 + name: "ImagePreview",
14 props: { 19 props: {
15 src: { 20 src: {
16 type: String, 21 type: String,
@@ -18,28 +23,40 @@ export default { @@ -18,28 +23,40 @@ export default {
18 }, 23 },
19 width: { 24 width: {
20 type: [Number, String], 25 type: [Number, String],
21 - default: '' 26 + default: ""
22 }, 27 },
23 height: { 28 height: {
24 type: [Number, String], 29 type: [Number, String],
25 - default: '' 30 + default: ""
26 } 31 }
27 }, 32 },
28 computed: { 33 computed: {
29 realSrc() { 34 realSrc() {
30 - if (isExternal(this.src)) {  
31 - return this.src 35 + let real_src = this.src.split(",")[0];
  36 + if (isExternal(real_src)) {
  37 + return real_src;
32 } 38 }
33 - return process.env.VUE_APP_BASE_API + this.src 39 + return process.env.VUE_APP_BASE_API + real_src;
  40 + },
  41 + realSrcList() {
  42 + let real_src_list = this.src.split(",");
  43 + let srcList = [];
  44 + real_src_list.forEach(item => {
  45 + if (isExternal(item)) {
  46 + return srcList.push(item);
  47 + }
  48 + return srcList.push(process.env.VUE_APP_BASE_API + item);
  49 + });
  50 + return srcList;
34 }, 51 },
35 realWidth() { 52 realWidth() {
36 - return typeof this.width == 'string' ? this.width : `${this.width}px` 53 + return typeof this.width == "string" ? this.width : `${this.width}px`;
37 }, 54 },
38 realHeight() { 55 realHeight() {
39 - return typeof this.height == 'string' ? this.height : `${this.height}px`  
40 - } 56 + return typeof this.height == "string" ? this.height : `${this.height}px`;
41 } 57 }
42 -} 58 + },
  59 +};
43 </script> 60 </script>
44 61
45 <style lang="scss" scoped> 62 <style lang="scss" scoped>