最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uniapp中uni-load-more的使用方式

 更新時(shí)間:2024年05月24日 09:01:03   作者:第7個(gè)前端  
這篇文章主要介紹了uniapp中uni-load-more的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

uniapp中uni-load-more使用

1 引入uniloadmore

import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
components: {uniLoadMore},

2 data中寫(xiě)的內(nèi)容

reload: false,
status: 'more',
contentText: {
        contentdown: '上拉加載更多~',
        contentrefresh: '加載中',
        contentnomore: '我是有底線(xiàn)的~'
},

3 template里面寫(xiě)的內(nèi)容

<uni-load-more :status="status" :icon-size="14" :content-text="contentText" v-if="dataList.length > 0" />

4 請(qǐng)求接口成功之后,判斷加載狀態(tài),處理數(shù)據(jù)

success: (result) => {
        this.totalCount = result.data.total
        if (result.data.total > 0) {
                const dataMap = result.data.list
                this.dataList = this.reload ? dataMap : this.dataList.concat(dataMap);
                this.reload = false;
        } else {
                this.dataList = [];
        }
        if (this.totalCount == this.dataList.length) {
                this.reload = false;
                this.status = 'noMore'
        }
}

5 監(jiān)控加載狀態(tài)

onReachBottom() {
        if (this.totalCount > this.dataList.length) {
                this.status = 'loading';
                setTimeout(() => {
                        this.pageNum++
                        this.getMonthTask();//執(zhí)行的方法
                }, 1000)//這里我是延遲一秒在加載方法有個(gè)loading效果,如果接口請(qǐng)求慢的話(huà)可以去掉
        } else { //停止加載
                this.status = 'noMore'
        }
},

uniapp - load-more觸底加載,下拉刷新

底部加載load-more(uni-ui組件)

三個(gè)狀態(tài):more、loading、nomore

  • 觸底事件:onReachBottom
  • 下拉刷新:onPullDownRefresh,停止下拉刷新uni.stopPullDownRefresh()
<template>
  <view>
    <!-- 底部加載,三個(gè)狀態(tài):more、loading、nomore -->
    <uni-load-more :status="status"></uni-load-more>
  </view>
</template>
 
<script>
export default {
  data() {
    return {
      data: null,
      status: 'more', //觸底加載狀態(tài)
      page: 1, //記錄當(dāng)前頁(yè)碼
    };
  },
  //觸底事件,請(qǐng)求數(shù)據(jù)、合并
  onReachBottom() {
    console.log('到底了到底了...');
    this.status = 'loading';
    this.getData(this.page + 1);
    this.page += 1;
  },
  //下拉刷新,請(qǐng)求第一頁(yè)
  onPullDownRefresh() {
    this.getData();
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData(page = 1) {
      uni.request({
        url: 'https://xxxx.....',
        method: 'GET',
        data: { page: page },
        success: res => {
          console.log(res);
          //如果頁(yè)數(shù)>1,需要拼接返回的數(shù)據(jù)
          if (page > 1) {
            res.data.result = [...this.data.result, ...res.data.result];
          }
          this.data = res.data;
          uni.stopPullDownRefresh(); //拿到數(shù)據(jù)后,停止下拉刷新
        },
        fail: () => {},
        complete: () => {}
      });
    },
  },
};
</script>

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

阳城县| 进贤县| 天气| 白玉县| 蕲春县| 罗田县| 黔西| 中山市| 章丘市| 永宁县| 宝坻区| 司法| 邵东县| 台南市| 桓台县| 怀宁县| 夏邑县| 沾化县| 霍邱县| 察雅县| 深泽县| 兴海县| 永和县| 常熟市| 宁国市| 阳江市| 乡城县| 三门县| 芦溪县| 宜兰市| 永州市| 大安市| 昭通市| 甘洛县| 罗平县| 琼海市| 南投县| 栾川县| 林口县| 自治县| 林州市|