img-preview.vue 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div class="preview" @click="onClick" @keydown="onKeydown">
  3. <div class="preview-img" >
  4. <img :src="src" alt />
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {};
  12. },
  13. props: {
  14. src: {
  15. type: String,
  16. default: "",
  17. required: true
  18. },
  19. onClick: { type: Function, default: () => {}, required: true },
  20. onKeydown: { type: Function, default: () => {}, required: true }
  21. }
  22. };
  23. </script>
  24. <style lang="scss" scoped>
  25. .preview {
  26. width: 100%;
  27. height: 100%;
  28. background: rgba(0, 0, 0, 0.5);
  29. position: fixed;
  30. top: 0;
  31. bottom: 0;
  32. left: 0;
  33. right: 0;
  34. z-index: 9999;
  35. overflow: scroll;
  36. cursor: pointer;
  37. display: flex;
  38. align-items: center;
  39. }
  40. .preview-img {
  41. padding: 20px;
  42. display: inline-block;
  43. margin: auto;
  44. img {
  45. max-width: 100%;
  46. max-height: 100%;
  47. }
  48. }
  49. </style>