image-format.uvue 3.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1;">
  <!-- #endif -->
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
      <!-- <view class="uni-title">
        <text class="uni-title-text">支持的图片格式示例</text>
      </view> -->
      <view v-for="(item,index) in supportFormats" :key="index">
        <text class="uni-subtitle-text">{{item.format}}</text>
        <view class="uni-center" style="background:#FFFFFF;">
          <!-- <image class="image" mode="widthFix" :src="item.src"></image> -->
          <image class="image" mode="widthFix" :src="item.errorImage == null ? item.src : item.errorImage"
            @error="imageErrorEvent(index, $event as ImageErrorEvent)"></image>
        </view>
      </view>
      <!-- <view class="uni-title">
        <text class="uni-title-text">暂不支持的格式</text>
      </view>
      <view v-for="(item,index) in notSupportFormats" :key="index">
        <text class="uni-subtitle-text">{{item.format}}</text>
        <view class="uni-center" style="background:#FFFFFF;">
          <image class="image" mode="widthFix" :src="item.errorImage == null ? item.src : item.errorImage"
            @error="imageErrorEvent(index, $event as ImageErrorEvent)"></image>
        </view>
      </view> -->
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script>
  export default {
    data() {
      return {
        title: 'image-format',
        supportFormats: [
          {
            format: 'bmp',
            src: '/static/test-image/logo.bmp'
          },
          {
            format: 'gif',
            src: '/static/test-image/logo.gif'
          },
          {
            format: 'ico',
            src: '/static/test-image/logo.ico'
          },
          {
            format: 'jpg',
            src: '/static/test-image/logo.jpg'
          },
          {
            format: 'png',
            src: '/static/test-image/logo.png'
          },
          {
            format: 'webp',
            src: '/static/test-image/logo.webp'
          },
          {
            format: 'heic(App-Android10+支持)',
            src: '/static/test-image/logo.heic'
          },
          {
            format: 'avif(仅部分浏览器支持)',
            src: '/static/test-image/logo.avif'
          },
          {
            format: 'tif(仅部分浏览器支持)',
            src: '/static/test-image/logo.tif'
          }
        ] as Array<ImageFormat>
        /* notSupportFormats: [
          {
            format: 'avif',
            src: '/static/test-image/logo.avif'
          },
          {
            format: 'tif',
            src: '/static/test-image/logo.tif'
          }
        ] as Array<ImageFormat> */
      }
    },
    methods: {
      imageErrorEvent(index : number, e : ImageErrorEvent) {
        console.log("图片加载错误", e.detail);
        // 图片加载失败,加载本地占位图
        this.supportFormats[index].errorImage = '/static/template/drop-card/dislike.png'
      }
    },
  }

  type ImageFormat = {
    format : string
    src : string.ImageURIString
    errorImage ?: string.ImageURIString | null
  }
</script>

<style>
  .image {
    margin: 40px auto;
    width: 100px;
  }
雪洛's avatar
雪洛 已提交
110
</style>