index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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">
  6. <u-toast ref="uToast"></u-toast>
  7. <view class="container u-skeleton">
  8. <view class="userinfo">
  9. <block>
  10. <!--u-skeleton-circle 绘制圆形-->
  11. <image class="userinfo-avatar u-skeleton-circle" :src="userInfo.avatarUrl"></image>
  12. <!--u-skeleton-fillet 绘制圆角矩形-->
  13. <text class="u-skeleton-fillet">{{userInfo.nickName}}</text>
  14. </block>
  15. </view>
  16. <view style="margin: 20px 0">
  17. <!--u-skeleton-rect 绘制矩形-->
  18. <view class="u-skeleton-rect lists" v-for="(item,index) in lists" :key="index">
  19. <text>{{item}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!--引用组件-->
  24. <u-skeleton bg-color="rgb(250, 250, 250)" :loading="loading" :animation="animation"
  25. :el-color="elColor" :border-radius="borderRadius"></u-skeleton>
  26. </view>
  27. </view>
  28. <view class="u-config-wrap">
  29. <view class="u-config-title u-border-bottom">
  30. 参数配置
  31. </view>
  32. <view class="u-config-item">
  33. <view class="u-item-title">加载状态</view>
  34. <u-subsection :current="current" :list="['请求中', '请求结束']" @change="loadingChange"></u-subsection>
  35. </view>
  36. <view class="u-config-item">
  37. <view class="u-item-title">骨架动画</view>
  38. <u-subsection current="1" :list="['是', '否']" @change="animationChange"></u-subsection>
  39. </view>
  40. <view class="u-config-item">
  41. <view class="u-item-title">自定义样式</view>
  42. <u-subsection current="1" :list="['是', '否']" @change="styleChange"></u-subsection>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. userInfo: {
  52. avatarUrl: 'https://cdn.uviewui.com/uview/common/logo.png',
  53. nickName: 'uView'
  54. },
  55. lists: [
  56. '君不见,黄河之水天上来,奔流到海不复回。君不见,高堂明镜悲白发,朝如青丝暮成雪。',
  57. '人生得意须尽欢,莫使金樽空对月',
  58. '天生我材必有用,千金散尽还复来',
  59. ],
  60. loading: true, // 是否显示骨架屏组件
  61. animation: false,
  62. elColor: '#e5e5e5',
  63. borderRadius: 10,
  64. }
  65. },
  66. computed: {
  67. current() {
  68. return this.loading ? 0 : 1;
  69. },
  70. },
  71. onLoad() {
  72. this.getData();
  73. },
  74. methods: {
  75. animationChange(index) {
  76. this.animation = index == 0 ? true : false;
  77. this.getData();
  78. },
  79. loadingChange(index) {
  80. this.loading = index == 0 ? true : false;
  81. if(index == 0) this.getData();
  82. },
  83. styleChange(index) {
  84. if(index == 0) {
  85. this.elColor = this.$u.color['primary'];
  86. this.borderRadius = 14;
  87. } else {
  88. this.elColor = '#e5e5e5';
  89. this.borderRadius = 10;
  90. }
  91. this.getData();
  92. },
  93. getData() {
  94. this.loading = true;
  95. // 通过延时模拟向后端请求数据,调隐藏骨架屏
  96. setTimeout(() => {
  97. this.loading = false;
  98. }, 3000)
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. .container {
  105. text-align: left;
  106. font-size: 28rpx;
  107. color: $u-content-color;
  108. }
  109. .userinfo {
  110. display: flex;
  111. flex-direction: column;
  112. align-items: center;
  113. }
  114. .userinfo-avatar {
  115. width: 128rpx;
  116. height: 128rpx;
  117. margin: 20rpx;
  118. border-radius: 50%;
  119. }
  120. .lists {
  121. margin: 10px 0;
  122. }
  123. </style>