image-mode.uvue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 data" :key="index">
  11. <text class="uni-subtitle-text">{{item.mode}}: {{item.description}}</text>
  12. <view class="uni-center" style="background:#FFFFFF;">
  13. <image class="image" :mode="item.mode" src="/static/shuijiao.jpg"></image>
  14. </view>
  15. </view>
  16. <view class="uni-title">
  17. <text class="uni-title-text">其他示例</text>
  18. </view>
  19. <view>
  20. <text class="uni-subtitle-text">同时设置mode和圆角</text>
  21. <view class="uni-center" style="background:#FFFFFF;">
  22. <image class="image radius" mode="heightFix" src="/static/shuijiao.jpg"></image>
  23. </view>
  24. </view>
  25. <view>
  26. <text class="uni-subtitle-text">设置图片width='100%'与mode='widthFix'</text>
  27. <view class="uni-center" style="background:#FFFFFF;">
  28. <view class="uni-center" style="background-color: red; width: 150px; margin: 20px;">
  29. <image style="width: 100%" mode="widthFix" src="/static/shuijiao.jpg"></image>
  30. </view>
  31. </view>
  32. </view>
  33. <view>
  34. <text class="uni-subtitle-text">image默认mode</text>
  35. <view class="uni-center" style="background:#FFFFFF;">
  36. <view class="uni-center" style="margin: 20px;">
  37. <image style="width: 100px; height: 100px;" src="/static/logo.png"></image>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- #ifdef APP -->
  43. </scroll-view>
  44. <!-- #endif -->
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. title: 'image-mode',
  51. data: [
  52. {
  53. mode: 'scaleToFill',
  54. description: '不保持纵横比缩放图片,使图片的宽高完全拉伸至填满 image 元素'
  55. },
  56. {
  57. mode: 'aspectFit',
  58. description: '保持纵横比缩放图片,使图片的长边能完全显示出来。也就是说,可以完整地将图片显示出来'
  59. },
  60. {
  61. mode: 'aspectFill',
  62. description: '保持纵横比缩放图片,只保证图片的短边能完全显示出来。也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发生截取'
  63. },
  64. {
  65. mode: 'top',
  66. description: '不缩放图片,只显示图片的顶部区域'
  67. },
  68. {
  69. mode: 'bottom',
  70. description: '不缩放图片,只显示图片的底部区域'
  71. },
  72. {
  73. mode: 'center',
  74. description: '不缩放图片,只显示图片的中间区域'
  75. },
  76. {
  77. mode: 'left',
  78. description: '不缩放图片,只显示图片的左边区域'
  79. },
  80. {
  81. mode: 'right',
  82. description: '不缩放图片,只显示图片的右边区域'
  83. },
  84. {
  85. mode: 'top left',
  86. description: '不缩放图片,只显示图片的左上边区域'
  87. },
  88. {
  89. mode: 'top right',
  90. description: '不缩放图片,只显示图片的右上边区域'
  91. },
  92. {
  93. mode: 'bottom left',
  94. description: '不缩放图片,只显示图片的左下边区域'
  95. },
  96. {
  97. mode: 'bottom right',
  98. description: '不缩放图片,只显示图片的右下边区域'
  99. },
  100. {
  101. mode: 'widthFix',
  102. description: '宽度不变,高度自动变化,保持原图宽高比不变'
  103. },
  104. {
  105. mode: 'heightFix',
  106. description: '高度不变,宽度自动变化,保持原图宽高比不变'
  107. }
  108. ] as Array<ImageMode>
  109. }
  110. }
  111. }
  112. type ImageMode = {
  113. mode : string
  114. description : string
  115. }
  116. </script>
  117. <style>
  118. .image {
  119. margin: 20px auto;
  120. width: 100px;
  121. height: 100px;
  122. background-color: #eeeeee;
  123. }
  124. .radius {
  125. border-radius: 10px;
  126. }
  127. </style>