image-format.uvue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1;">
  4. <!-- #endif -->
  5. <page-head :title="title"></page-head>
  6. <view class="uni-padding-wrap uni-common-mt">
  7. <!-- <view class="uni-title">
  8. <text class="uni-title-text">支持的图片格式示例</text>
  9. </view> -->
  10. <view v-for="(item,index) in supportFormats" :key="index">
  11. <text class="uni-subtitle-text">{{item.format}}</text>
  12. <view class="uni-center" style="background:#FFFFFF;">
  13. <!-- <image class="image" mode="widthFix" :src="item.src"></image> -->
  14. <image class="image" mode="widthFix" :src="item.errorImage == null ? item.src : item.errorImage"
  15. @error="imageErrorEvent(index, $event as ImageErrorEvent)"></image>
  16. </view>
  17. </view>
  18. <!-- <view class="uni-title">
  19. <text class="uni-title-text">暂不支持的格式</text>
  20. </view>
  21. <view v-for="(item,index) in notSupportFormats" :key="index">
  22. <text class="uni-subtitle-text">{{item.format}}</text>
  23. <view class="uni-center" style="background:#FFFFFF;">
  24. <image class="image" mode="widthFix" :src="item.errorImage == null ? item.src : item.errorImage"
  25. @error="imageErrorEvent(index, $event as ImageErrorEvent)"></image>
  26. </view>
  27. </view> -->
  28. </view>
  29. <!-- #ifdef APP -->
  30. </scroll-view>
  31. <!-- #endif -->
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. title: 'image-format',
  38. supportFormats: [
  39. {
  40. format: 'bmp',
  41. src: '/static/test-image/logo.bmp'
  42. },
  43. {
  44. format: 'gif',
  45. src: '/static/test-image/logo.gif'
  46. },
  47. {
  48. format: 'ico',
  49. src: '/static/test-image/logo.ico'
  50. },
  51. {
  52. format: 'jpg',
  53. src: '/static/test-image/logo.jpg'
  54. },
  55. {
  56. format: 'png',
  57. src: '/static/test-image/logo.png'
  58. },
  59. {
  60. format: 'webp',
  61. src: '/static/test-image/logo.webp'
  62. },
  63. {
  64. format: 'heic(App-Android10+支持)',
  65. src: '/static/test-image/logo.heic'
  66. },
  67. {
  68. format: 'avif(仅部分浏览器支持)',
  69. src: '/static/test-image/logo.avif'
  70. },
  71. {
  72. format: 'tif(仅部分浏览器支持)',
  73. src: '/static/test-image/logo.tif'
  74. },
  75. {
  76. format: 'svg(iOS、Android 暂不支持)',
  77. src: '/static/test-image/logo.svg'
  78. }
  79. ] as Array<ImageFormat>
  80. /* notSupportFormats: [
  81. {
  82. format: 'avif',
  83. src: '/static/test-image/logo.avif'
  84. },
  85. {
  86. format: 'tif',
  87. src: '/static/test-image/logo.tif'
  88. }
  89. ] as Array<ImageFormat> */
  90. }
  91. },
  92. methods: {
  93. imageErrorEvent(index : number, e : ImageErrorEvent) {
  94. console.log("图片加载错误", e.detail);
  95. // 图片加载失败,加载本地占位图
  96. this.supportFormats[index].errorImage = '/static/template/drop-card/dislike.png'
  97. }
  98. },
  99. }
  100. type ImageFormat = {
  101. format : string
  102. src : string.ImageURIString
  103. errorImage ?: string.ImageURIString | null
  104. }
  105. </script>
  106. <style>
  107. .image {
  108. margin: 40px auto;
  109. width: 100px;
  110. }
  111. </style>