image.uvue 2.8 KB

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