index.vue 1.6 KB

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