NodeImg.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div :class="[ui, mode,filter?'filter-' + filter:'']" :style="[{ width: width }, { height: height }]" class="ui-img-box" @click="_imgClick">
  3. <img :class="mode" :src="src" alt="" class="ui-img" @error="_error" @load="_load"/>
  4. </div>
  5. </template>
  6. <script setup>
  7. const props = defineProps({
  8. ui: {
  9. type: String,
  10. default: ''
  11. },
  12. src: {
  13. type: String,
  14. default: ''
  15. },
  16. mode: {
  17. type: String,
  18. default: 'cover'
  19. },
  20. filter: {
  21. type: String,
  22. default: ''
  23. },
  24. width: {
  25. type: String,
  26. default: 'auto'
  27. },
  28. height: {
  29. type: String,
  30. default: '140px'
  31. },
  32. })
  33. //事件
  34. const emit = defineEmits(['load', 'error', 'imgClick']);
  35. //图片加载完毕
  36. const _load = () => {
  37. emit('load')
  38. }
  39. //图片加载出错
  40. const _error = () => {
  41. emit('error')
  42. }
  43. //图片被点击
  44. const _imgClick = () => {
  45. emit('imgClick', props.src)
  46. }
  47. </script>
  48. <style lang="scss" scoped>
  49. .ui-img-box {
  50. position: relative;
  51. width: auto;
  52. height: 140px;
  53. display: inline-block;
  54. z-index: 2;
  55. .ui-img {
  56. width: 100%;
  57. height: 100%;
  58. z-index: -1;
  59. border-radius: inherit;
  60. }
  61. &.cover {
  62. background-size: cover;
  63. }
  64. }
  65. </style>