index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <el-image :src="`${realSrc}`" fit="cover" :style="`width:${realWidth};height:${realHeight};`" :preview-src-list="[`${realSrc}`]">
  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>
  11. import { isExternal } from '@/utils/validate'
  12. const props = defineProps({
  13. src: {
  14. type: String,
  15. required: true
  16. },
  17. width: {
  18. type: [Number, String],
  19. default: ''
  20. },
  21. height: {
  22. type: [Number, String],
  23. default: ''
  24. }
  25. });
  26. const realSrc = computed(() => {
  27. if (isExternal(props.src)) {
  28. return props.src
  29. }
  30. return import.meta.env.VITE_APP_BASE_API + props.src
  31. })
  32. const realWidth = computed(
  33. () => typeof props.width == 'string' ? props.width : `${props.width}px`
  34. );
  35. const realHeight = computed(
  36. () => typeof props.height == 'string' ? props.height : `${props.height}px`
  37. );
  38. </script>
  39. <style lang="scss" scoped>
  40. .el-image {
  41. border-radius: 5px;
  42. background-color: #ebeef5;
  43. box-shadow: 0 0 5px 1px #ccc;
  44. :deep(.el-image__inner) {
  45. transition: all 0.3s;
  46. cursor: pointer;
  47. &:hover {
  48. transform: scale(1.2);
  49. }
  50. }
  51. :deep(.image-slot) {
  52. display: flex;
  53. justify-content: center;
  54. align-items: center;
  55. width: 100%;
  56. height: 100%;
  57. color: #909399;
  58. font-size: 30px;
  59. }
  60. }
  61. </style>