selectedImageInEditor.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div class="img-wrapper">
  3. <img :src="realImage || defaultImgSrc" alt="" />
  4. <div v-if="realImage" class="cancel-btn-background" @click="handleCancel">
  5. <i class="iconfont icon-close"></i>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. realImage: "",
  14. };
  15. },
  16. props: {
  17. imgSrc: {
  18. type: String,
  19. default: "",
  20. },
  21. defaultImgSrc: {
  22. type: String,
  23. require: true,
  24. },
  25. },
  26. watch: {
  27. imgSrc: {
  28. handler(val) {
  29. this.realImage = val;
  30. },
  31. immediate: true,
  32. deep: true,
  33. },
  34. },
  35. methods: {
  36. handleCancel() {
  37. console.log("select_image-component-cancel");
  38. this.realImage = "";
  39. this.$emit("cancel");
  40. },
  41. },
  42. };
  43. </script>
  44. <style lang="less" scoped>
  45. .img-wrapper {
  46. flex: 0 0 auto;
  47. position: relative;
  48. width: 136px;
  49. height: 136px;
  50. margin-right: 16px;
  51. background: #1a1b1d;
  52. border-radius: 4px;
  53. border: 1px solid #404040;
  54. overflow: hidden;
  55. > img {
  56. width: 100%;
  57. height: 100%;
  58. object-fit: contain;
  59. }
  60. > .cancel-btn-background {
  61. width: 52px;
  62. height: 52px;
  63. position: absolute;
  64. top: -28px;
  65. right: -28px;
  66. background: rgba(0, 0, 0, 0.5);
  67. border-radius: 50%;
  68. cursor: pointer;
  69. &:hover {
  70. color: #fa5555;
  71. }
  72. > i {
  73. font-size: 12px;
  74. transform: scale(0.8);
  75. position: absolute;
  76. left: 9px;
  77. bottom: 9px;
  78. }
  79. }
  80. }
  81. </style>