image-mode.uvue 3.9 KB
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1
<template>
2
  <!-- #ifdef APP -->
H
hdx 已提交
3
  <scroll-view style="flex: 1;">
4
  <!-- #endif -->
H
hdx 已提交
5 6
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
7
      <view class="uni-title">
H
hdx 已提交
8 9 10 11 12 13 14 15 16 17
        <text class="uni-title-text">支持的图片缩放模式示例</text>
      </view>
      <view v-for="(item,index) in data" :key="index">
        <text class="uni-subtitle-text">{{item.mode}}: {{item.description}}</text>
        <view class="uni-center" style="background:#FFFFFF;">
          <image class="image" :mode="item.mode" src="/static/shuijiao.jpg"></image>
        </view>
      </view>
      <view class="uni-title">
        <text class="uni-title-text">其他示例</text>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
18 19 20 21
      </view>
      <view>
        <text class="uni-subtitle-text">同时设置mode和圆角</text>
        <view class="uni-center" style="background:#FFFFFF;">
H
hdx 已提交
22
          <image class="image radius" mode="heightFix" src="/static/shuijiao.jpg"></image>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
23 24
        </view>
      </view>
shutao-dc's avatar
shutao-dc 已提交
25 26 27 28 29 30 31 32
      <view>
        <text class="uni-subtitle-text">设置图片width='100%'与mode='widthFix'</text>
        <view class="uni-center" style="background:#FFFFFF;">
          <view class="uni-center" style="background-color: red; width: 150px; margin: 20px;">
            <image style="width: 100%" mode="widthFix" src="/static/shuijiao.jpg"></image>
          </view>
        </view>
      </view>
H
hdx 已提交
33
    </view>
34
  <!-- #ifdef APP -->
H
hdx 已提交
35
  </scroll-view>
36
  <!-- #endif -->
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
37 38 39
</template>

<script>
H
hdx 已提交
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
  export default {
    data() {
      return {
        title: 'image-mode',
        data: [
          {
            mode: 'scaleToFill',
            description: '不保持纵横比缩放图片,使图片的宽高完全拉伸至填满 image 元素'
          },
          {
            mode: 'aspectFit',
            description: '保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来'
          },
          {
            mode: 'aspectFill',
            description: '保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取'
          },
          {
            mode: 'top',
            description: '不缩放图片,只显示图片的顶部区域'
          },
          {
            mode: 'bottom',
            description: '不缩放图片,只显示图片的底部区域'
          },
          {
            mode: 'center',
            description: '不缩放图片,只显示图片的中间区域'
          },
          {
            mode: 'left',
            description: '不缩放图片,只显示图片的左边区域'
          },
          {
            mode: 'right',
            description: '不缩放图片,只显示图片的右边区域'
          },
          {
            mode: 'top left',
            description: '不缩放图片,只显示图片的左上边区域'
          },
          {
            mode: 'top right',
            description: '不缩放图片,只显示图片的右上边区域'
          },
          {
            mode: 'bottom left',
            description: '不缩放图片,只显示图片的左下边区域'
          },
          {
            mode: 'bottom right',
            description: '不缩放图片,只显示图片的右下边区域'
          },
          {
            mode: 'widthFix',
            description: '宽度不变,高度自动变化,保持原图宽高比不变'
          },
          {
            mode: 'heightFix',
            description: '高度不变,宽度自动变化,保持原图宽高比不变'
          }
        ] as Array<ImageMode>
      }
    }
  }

  type ImageMode = {
    mode : string
    description : string
  }
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
110 111 112
</script>

<style>
H
hdx 已提交
113 114 115 116 117 118
  .image {
    margin: 20px auto;
    width: 100px;
    height: 100px;
    background-color: #eeeeee;
  }
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
119 120

  .radius {
H
hdx 已提交
121
    border-radius: 10px;
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
122 123
  }
</style>