image.uvue 2.6 KB
Newer Older
Y
init  
yurj26 已提交
1
<template>
H
hdx 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  <view style="flex: 1;">
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
      <view class="uni-center" style="background:#FFFFFF;">
        <image class="image" :fade-show="true" mode="widthFix" :src="imageSrc" @error="error" @load="load"></image>
      </view>
      <view class="uni-btn-v">
        <button type="primary" @tap="imageFormat">图片格式示例</button>
      </view>
      <view class="uni-btn-v">
        <button type="primary" @tap="imageMode">图片缩放模式示例</button>
      </view>
      <view class="uni-btn-v">
        <button type="primary" @tap="imagePath">图片路径示例</button>
      </view>
      <view class="uni-btn-v">
        <button type="primary" @tap="imageLarge">大图示例</button>
      </view>
20 21 22 23
    </view>
    <view v-if="autoTest">
      <image :src="setCookieImage"></image>
      <image :src="verifyCookieImage" @error="error"></image>
H
hdx 已提交
24 25
    </view>
  </view>
Y
init  
yurj26 已提交
26 27
</template>
<script>
H
hdx 已提交
28 29 30 31
  export default {
    data() {
      return {
        title: 'image',
W
wanganxp 已提交
32
        imageSrc: "/static/test-image/logo.png" as string.ImageURIString,
33 34 35 36
        loadError: false,
        // 自动化测试
        autoTest: false,
        setCookieImage: "",
37
        verifyCookieImage: "",
雪洛's avatar
雪洛 已提交
38 39
        eventLoad: null as UTSJSONObject | null,
        eventError: null as UTSJSONObject | null
H
hdx 已提交
40 41 42 43 44
      }
    },
    methods: {
      error(event : ImageErrorEvent) {
        this.loadError = true
45 46 47 48 49 50 51 52
        console.log(event.type, event.detail);
        if (this.autoTest) {
          this.eventError = {
            "tagName": event.target?.tagName,
            "type": event.type,
            // "errMsg": event.detail.errMsg
          };
        }
H
hdx 已提交
53 54
      },
      load(event : ImageLoadEvent) {
55 56 57 58 59 60 61 62 63
        console.log(event.type, event.detail);
        if (this.autoTest) {
          this.eventLoad = {
            "tagName": event.target?.tagName,
            "type": event.type,
            "width": event.detail.width,
            "height": event.detail.height
          };
        }
H
hdx 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
      },
      imageFormat() {
        uni.navigateTo({
          url: '/pages/component/image/image-format'
        });
      },
      imageMode() {
        uni.navigateTo({
          url: '/pages/component/image/image-mode'
        });
      },
      imagePath() {
        uni.navigateTo({
          url: '/pages/component/image/image-path'
        });
      },
      imageLarge() {
        uni.navigateTo({
          url: '/pages/component/image/image-large'
        });
      }
    }
  }
Y
init  
yurj26 已提交
87 88
</script>
<style>
H
hdx 已提交
89 90 91 92
  .image {
    margin: 20px auto;
    width: 100px;
  }
shutao-dc's avatar
shutao-dc 已提交
93
</style>