index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="u-demo">
  3. <view class="u-demo-wrap">
  4. <view class="u-demo-title">演示效果</view>
  5. <view class="u-demo-area u-flex u-row-center">
  6. <u-image :shape="shape" ref="uImage" :width="width" :height="height" :src="src" mode="aspectFill">
  7. <u-loading size="44" mode="flower" slot="loading" v-if="loadingSlot"></u-loading>
  8. <view v-if="errorSlot" slot="error" style="font-size: 24rpx;">加载失败</view>
  9. </u-image>
  10. </view>
  11. </view>
  12. <view class="u-config-wrap">
  13. <view class="u-config-title u-border-bottom">参数配置</view>
  14. <view class="u-config-item">
  15. <view class="u-item-title">状态</view>
  16. <u-subsection :current="statusCurrent" :list="['加载成功', '加载中', '加载失败']" @change="statusChange"></u-subsection>
  17. </view>
  18. <!-- 微信小程序中,无法动态切换slot,所以隐藏此部分的演示 -->
  19. <!-- #ifndef MP-WEIXIN -->
  20. <view class="u-config-item">
  21. <view class="u-item-title">加载中状态</view>
  22. <u-subsection :list="['默认', '自定义']" @change="loadingChange"></u-subsection>
  23. </view>
  24. <!-- #endif -->
  25. <view class="u-config-item">
  26. <view class="u-item-title">加载失败状态</view>
  27. <u-subsection :list="['默认', '自定义']" @change="errorChange"></u-subsection>
  28. </view>
  29. <view class="u-config-item">
  30. <view class="u-item-title">形状</view>
  31. <u-subsection :list="['方形', '圆形']" @change="shapeChange"></u-subsection>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. src: 'https://cdn.uviewui.com/uview/example/fade.jpg',
  41. width: '200',
  42. height: '200',
  43. loadingSlot: false,
  44. statusCurrent: 0,
  45. errorSlot: false,
  46. shape: 'square'
  47. };
  48. },
  49. computed: {
  50. // statusCurrent() {
  51. // }
  52. },
  53. methods: {
  54. statusChange(index) {
  55. // 此处通过ref操作组件内部状态,仅是为了演示使用,实际中无需这些操作,由内部的图片加载事件自动完成
  56. if (index == 0) {
  57. this.src = 'http://img5.imgtn.bdimg.com/it/u=2438062088,2808868405&fm=26&gp=0.jpg';
  58. this.$refs.uImage.loading = false;
  59. this.$refs.uImage.isError = false;
  60. } else if (index == 1) {
  61. this.$refs.uImage.loading = true;
  62. } else {
  63. this.$refs.uImage.loading = false;
  64. this.$refs.uImage.isError = true;
  65. }
  66. },
  67. loadingChange(index) {
  68. this.statusCurrent = 1;
  69. this.statusChange(1);
  70. if (index == 0) {
  71. this.loadingSlot = false;
  72. } else {
  73. this.loadingSlot = true;
  74. }
  75. },
  76. errorChange(index) {
  77. this.statusCurrent = 2;
  78. this.statusChange(2);
  79. if (index == 0) {
  80. this.errorSlot = false;
  81. } else {
  82. this.errorSlot = true;
  83. }
  84. },
  85. shapeChange(index) {
  86. this.shape = index == 0 ? 'square' : 'circle';
  87. }
  88. }
  89. };
  90. </script>
  91. <style scoped lang="scss">
  92. .u-demo-area {
  93. }
  94. </style>