index.vue 1.6 KB

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