oa-image.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <block>
  3. <image
  4. v-if="preview"
  5. class="oa-image"
  6. mode="mode"
  7. lazy-load="true"
  8. @tap.stop="previewImage(src)"
  9. @error="onImageError"
  10. :src="src || $mAssetsPath.errorImage"
  11. ></image>
  12. <image
  13. v-else
  14. class="oa-image"
  15. mode="mode"
  16. lazy-load="true"
  17. @error="onImageError"
  18. :src="src || $mAssetsPath.errorImage"
  19. ></image>
  20. </block>
  21. </template>
  22. <script>
  23. /**
  24. * @des 图片标签的建议封装
  25. *
  26. * @author hjp1011 21931118@qq.com
  27. * @date 2020-03-10 15:33
  28. * @copyright 2020
  29. */
  30. import $mAssetsPath from '@/config/assets.config';
  31. export default {
  32. name: 'rfImage',
  33. props: {
  34. src: {
  35. type: String,
  36. default: $mAssetsPath.errorImage
  37. },
  38. // 显示模式
  39. mode: {
  40. type: String,
  41. default: 'aspectFill'
  42. },
  43. // 是否预览
  44. preview: {
  45. type: Boolean,
  46. default: true
  47. }
  48. },
  49. methods: {
  50. // 图片异常处理
  51. onImageError() {
  52. this.src = $mAssetsPath.errorImage;
  53. },
  54. // 图片预览
  55. previewImage(urls) {
  56. if (!this.preview) return;
  57. if (!urls) return;
  58. uni.previewImage({
  59. urls: urls.split('#$#')
  60. });
  61. }
  62. }
  63. };
  64. </script>
  65. <style lang="scss">
  66. .oa-image {
  67. width: 100%;
  68. height: 100%;
  69. }
  70. </style>