微信小程序skeleton骨架屏

2020-09-02 16:35:07 浏览数 (2)

github链接地址

代码语言:javascript复制
https://github.com/jayZOU/skeleton.git

克隆dist文件放入到项目component目录中

page页面引入

代码语言:javascript复制
{
  "usingComponents": {
    "skeleton": "../../component/skeleton/skeleton"
  },
}

文本添加class=“skeleton-rect”, 图片添加class=“skeleton-radius”

代码语言:javascript复制
<skeleton wx:if="{{isSkeleton}}" loading="chiaroscuro"></skeleton>
<view class="box skeleton">
    <view class="row" wx:for="{{list}}" wx:key="index">
        <view class="name">
            <view class="skeleton-rect">{{item.name}}</view>
            <view class="skeleton-rect">置顶</view>
        </view>
        <view class="col">
            <view class="skeleton-rect">{{item.phone}}</view>
            <view class="skeleton-rect">{{item.address}}</view>
        </view>
        <view class="upload flexCenter">
            <image class="skeleton-radius" src="https://sucai.suoluomei.cn/sucai_zs/images/20200804180525-63.png"
                mode="widthFix"></image>
        </view>
    </view>
</view>
代码语言:javascript复制
Page({
  data: {
    isSkeleton: true,
    list: []
  },
  
  onLoad: function (options) {
    var array = [{
      name: "xxx",
      phone: "xxxxxxxxxxxxxx",
      address: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }, {
      name: "xxx",
      phone: "xxxxxxxxxxxxxx",
      address: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }, {
      name: "xxx",
      phone: "xxxxxxxxxxxxxx",
      address: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }]
    this.setData({
      list: array
    })
    setTimeout(() => {
      this.setData({
        isSkeleton: false
      })
    }, 2000)
  },
})

0 人点赞