index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <el-image :src="`${realSrc}`" fit="cover" :style="`width:${realWidth};height:${realHeight};`" :preview-src-list="[`${realSrc}`]">
  3. <div slot="error" class="image-slot">
  4. <i class="el-icon-picture-outline"></i>
  5. </div>
  6. </el-image>
  7. </template>
  8. <script>
  9. import { isExternal } from '@/utils/validate'
  10. export default {
  11. name: 'ImagePreview',
  12. props: {
  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. computed: {
  27. realSrc() {
  28. if (isExternal(this.src)) {
  29. return this.src
  30. }
  31. return process.env.VUE_APP_BASE_API + this.src
  32. },
  33. realWidth() {
  34. return typeof this.width == 'string' ? this.width : `${this.width}px`
  35. },
  36. realHeight() {
  37. return typeof this.height == 'string' ? this.height : `${this.height}px`
  38. }
  39. }
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .el-image {
  44. border-radius: 5px;
  45. background-color: #ebeef5;
  46. box-shadow: 0 0 5px 1px #ccc;
  47. ::v-deep .el-image__inner {
  48. transition: all 0.3s;
  49. cursor: pointer;
  50. &:hover {
  51. transform: scale(1.2);
  52. }
  53. }
  54. ::v-deep .image-slot {
  55. display: flex;
  56. justify-content: center;
  57. align-items: center;
  58. width: 100%;
  59. height: 100%;
  60. color: #909399;
  61. font-size: 30px;
  62. }
  63. }
  64. </style>