image-path.uvue 9.2 KB
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2 3 4 5 6 7 8 9 10 11 12 13
  <scroll-view>
    <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 data" :key="index">
        <text class="uni-subtitle-text">{{item.description}}</text>
        <view class="uni-center" style="background:#FFFFFF;">
          <image class="image" mode="widthFix" :src="item.src" @error="imageErrorEvent"></image>
        </view>
      </view>
W
wanganxp 已提交
14 15 16 17 18 19
      <view>
        <text class="uni-subtitle-text">非static目录的src静态路径:./logo.png</text>
        <view class="uni-center" style="background:#FFFFFF;">
          <image class="image" mode="widthFix" src="./logo.png" @error="imageErrorEvent"></image>
        </view>
      </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
20 21
    </view>
  </scroll-view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
22 23 24
</template>

<script>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  import logo from './logo.png';
  export default {
    data() {
      return {
        title: 'image-path',
        data: [
          {
            src: '/static/test-image/logo.png',
            description: '本地路径:/static方式'
          },
          {
            src: '../../../static/test-image/logo.png',
            description: '本地路径:../static/'
          },
          {
            src: '../../../static/Test-Image/Logo.png',
41
            description: '本地相对路径忽略大小写(需注意Android打包后无效)'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
42 43 44
          },
          {
            src: logo,
W
wanganxp 已提交
45
            description: 'import方式'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
46 47 48
          },
          {
            // #ifdef APP-ANDROID
W
微调  
wanganxp 已提交
49
            src: 'file:///storage/emulated/0/Android/data/io.dcloud.uniappx/apps/__UNI__3584C99/www/static/test-image/logo.png',
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
50
            // #endif
W
微调  
wanganxp 已提交
51
            // TODO iOS发版时还需再补路径
52
            description: '本地绝对路径file://方式(需注意打包后包名appid匹配)'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
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
          },
          {
            src: 'testerror.jpg',
            description: '错误的本地路径'
          },
          {
            src: 'data:image/*;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAYAAABS3GwHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABZ0RVh0Q3JlYXRpb24gVGltZQAwNS8xMi8yM3CzGsQAAAAcdEVYdFNvZnR3YXJlAEFkb2JlIEZpcmV3b3JrcyBDUzbovLKMAAAQGUlEQVR4nO3df5ScVX3H8ffMLpsfBDCkQrQQQiAhHq5EIog+IAKCpwqHcFQKTbQg2AultLUiUDg5gNZfh2CFWjl45UBpg5IaUYugRUsSoDdIUBO9QhAhIYQ0AUlIQn4nO/3jPgPDZmd3Zp4f95mZ7+ucPezOPj8+WZ7v3DvPj3tLlUoFkR5lojJwCDAROAw4PP4aDxwMjAP2B0YBfUAJ2AnsADYD64F18dfzwIqa/6522m7L71/T+UpSAK1RJtoPmAAcARwJTIp/Phj4E2A/YDSwD9ALlJvcRQXYDewCtgFbgFeAl4BVwErgD/HXSqft+kT/oC4lBdAAZaIe4CjgOOA9wLH4g/6gkLlqbACeA34L/BJYAjin7ZagqdqAFEAdykRHAe8HTsMf+JPDJmraGnwxPAwsBJY5bXcFTVRAUgAxZaIRQAR8BDgdmIbvn3eKZ4EFwAPAQqfthsB5CqGrC0CZqBf/Ln8u8Gf4D6vd4I/4YpgP/LfTdmPgPMF0ZQEoEyngfODj+L59N1sL/Bi422m7MGiSALqmAJSJRgFnAxcBZ9BZ3Zu0LAX+DbjHabsucJZcdHwBKBP9KfAp/IHfLV2cp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VQpE10CXIdcPAtlB3Az/qruxtBhWtHWBQCgTDQOuBr4W2Bk4Djd5HvA5522vwsdJIm2L4AqZaIpwLXAJ2mjzzZt6OfAl5y2C8PGSEfHFECVMtG78LMFzkQKIU0LgDlO25+EDpKmjiuAKmWiafhhGmciV5OTeAC4xWn7YOggWejYAqhSJjoCP4vNBciH5UZtwffxb3PaFmI20Kx0fAFUKRPtD5wLfAq527Se5fiHVOY6bZ8PHSYPXVMAteLrCLOAc4BDA8cJbQPwE/yB/6DTdk/gPLnqygKoUibaFzgN3zKcDrwtbKLcvAYsAuYDD4R4GL0ouroAaikT7Qd8ADgLOBWYEjZR6tYADwP3Aw/FI3h3PSmAQSgT9QDH4B/OOQWYDhwSMFIr1uPH2nkUfwpzidN2S9hIxSMF0ABlotHA0fib8Y4HpgGTgKLMzr0Vfz+OA57ATyX0G6ftK0FTtQEpgBbFt2BMBCbHX4fjP1AfBBwIjMHfmtEbf7WiH9iFn2jkNfytxi8Dq4GVwDPA74EVTtv/a3EfXU0KIGXx6dZDgSOBCfjPEhPw1yDGA+OAUXVW34k/K7MO32dfjT/AV+EP9hfyHjqw0/0/VOBpKm24LQkAAAAASUVORK5CYII=',
            description: 'Base64'
          },
          {
            src: 'https://request.dcloud.net.cn/api/http/contentType/image/png',
            description: '正确网络路径'
          },
          {
            src: 'https://request.dcloud.net.cn/api/http/contentType/wrongImage/gif',
            description: '错误网络格式,假gif实为jpeg'
          },
          {
            src: 'https://request.dcloud.net.cn/api/http/contentType/wrongImage/jpeg',
            description: '错误网络格式,假jpg实为png'
          },
          {
            src: 'https://request.dcloud.net.cn/api/http/contentType/wrongImage/png',
            description: '错误网络格式,假png实为gif'
          },
          {
            src: 'https://request.dcloud.net.cn/api/http/contentType/404',
            description: '错误网络地址404接口'
          },
          {
            src: 'https://request.dcloud.net.cn/api/http/contentType/404.png',
            description: '错误网络地址,不存在的图片'
W
wanganxp 已提交
85 86 87 88
          },
          {
            src: './logo.png',
            description: '非static目录的动态路径(不显示是对的)'
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
89 90 91 92 93 94 95 96 97 98 99 100
          }
        ] as Array<ImagePath>
      }
    },
    methods: {
      imageErrorEvent(e : ImageErrorEvent) {
        console.log("图片加载错误", e.detail);
        // 图片加载失败,加载本地占位图
        e.target?.setAttribute('src', '/static/template/drop-card/dislike.png')
      }
    },
  }
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
101

DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
102 103 104 105
  type ImagePath = {
    src : string
    description : string
  }
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
106 107 108
</script>

<style>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
109 110 111 112
  .image {
    margin: 40rpx auto;
    width: 200rpx;
  }
W
微调  
wanganxp 已提交
113
</style>