index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <el-image
  3. :src="`${realSrc}`"
  4. fit="cover"
  5. :style="`width:${realWidth};height:${realHeight};`"
  6. :preview-src-list="realSrcList"
  7. >
  8. <div slot="error" class="image-slot">
  9. <i class="el-icon-picture-outline"></i>
  10. </div>
  11. </el-image>
  12. </template>
  13. <script>
  14. export default {
  15. name: "ImagePreview",
  16. props: {
  17. src: {
  18. type: String,
  19. required: true
  20. },
  21. width: {
  22. type: [Number, String],
  23. default: ""
  24. },
  25. height: {
  26. type: [Number, String],
  27. default: ""
  28. }
  29. },
  30. computed: {
  31. realSrc() {
  32. let real_src = this.src.split(",")[0];
  33. return real_src;
  34. },
  35. realSrcList() {
  36. let real_src_list = this.src.split(",");
  37. let srcList = [];
  38. real_src_list.forEach(item => {
  39. return srcList.push(item);
  40. });
  41. return srcList;
  42. },
  43. realWidth() {
  44. return typeof this.width == "string" ? this.width : `${this.width}px`;
  45. },
  46. realHeight() {
  47. return typeof this.height == "string" ? this.height : `${this.height}px`;
  48. }
  49. },
  50. };
  51. </script>
  52. <style lang="scss" scoped>
  53. .el-image {
  54. border-radius: 5px;
  55. background-color: #ebeef5;
  56. box-shadow: 0 0 5px 1px #ccc;
  57. ::v-deep .el-image__inner {
  58. transition: all 0.3s;
  59. cursor: pointer;
  60. &:hover {
  61. transform: scale(1.2);
  62. }
  63. }
  64. ::v-deep .image-slot {
  65. display: flex;
  66. justify-content: center;
  67. align-items: center;
  68. width: 100%;
  69. height: 100%;
  70. color: #909399;
  71. font-size: 30px;
  72. }
  73. }
  74. </style>