1
0

app-image.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view class="app-image" :style="appBackground" v-if="imgSrc">
  3. <image src="./../../../static/image/icon/loading-img.png" class="img" :class="is_error ? '' : 'default'"
  4. mode="aspectFill" lazy-load v-if="is_loading" :style="imgStyle"></image>
  5. <image :src="imgSrc" class="img" :mode="mode" @error="imgError" @load="imgLoad" lazy-load
  6. v-if="!is_error" :style="imgStyle"></image>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name: "app-image",
  12. props: {
  13. imgSrc: String,
  14. width: String,
  15. height: String,
  16. mode: {
  17. type: String,
  18. default() {
  19. return 'aspectFill';
  20. }
  21. },
  22. borderRadius: String,
  23. },
  24. data() {
  25. return {
  26. is_loading: true,
  27. is_error: false
  28. };
  29. },
  30. computed: {
  31. appBackground() {
  32. return `width: ${this.width};height: ${this.height};`;
  33. },
  34. imgStyle() {
  35. return `border-radius: ${this.borderRadius}`;
  36. },
  37. },
  38. methods: {
  39. imgError() {
  40. this.is_error = true;
  41. },
  42. imgLoad() {
  43. this.is_loading = false;
  44. }
  45. }
  46. }
  47. </script>
  48. <style scoped lang="scss">
  49. .app-image {
  50. display: block;
  51. position: relative;
  52. .img {
  53. width: 100%;
  54. height: 100%;
  55. display: block;
  56. will-change: transform;
  57. &.default {
  58. position: absolute;
  59. left: 0;
  60. top: 0;
  61. z-index: 0;
  62. }
  63. }
  64. }
  65. </style>