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

使用Vant如何實(shí)現(xiàn)數(shù)據(jù)分頁,下拉加載

 更新時(shí)間:2022年06月28日 15:24:11   作者:倘若hfl  
這篇文章主要介紹了使用Vant實(shí)現(xiàn)數(shù)據(jù)分頁及下拉加載方式。具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Vant-ui的van-list實(shí)現(xiàn)數(shù)據(jù)分頁加載

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vant數(shù)據(jù)分頁,下拉加載</title>
  <link rel="stylesheet"  rel="external nofollow"  />
</head>
<style>
</style>
<body>
  <div id='app'>
    <van-list class="lazy" v-model="loading" :finished="finished" finished-text="沒有更多了" @load="onLoad"
      :immediate-check="false">
      <div v-for="(item,index) in list" :key="index">{{item}}</div>
    </van-list>
  </div>
</body>
<script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vant@2.11/lib/vant.min.js"></script>
<script>
  var Vue = new Vue({
    el: '#app',
    data: {
      list: [],
      page: 1,
      loading: false,
      finished: false,
      num: 0
    },
    created() {
      this.getList()
    },
    mounted() {
    },
    methods: {
      // 請求公共方法
      ajax(url, params, cb) {
        $.ajax({
          type: 'post',
          url: url,
          data: params,
          dataType: "json",
          success: function (response) {
            cb(response)
          }
        });
      },
      onLoad() {
        this.getList()
      },
      getList() {
        let that = this
        that.ajax('url', { kay: 'value' }, function (res) {
          if (res.errcode != 0) {
            that.$toast(res.msg)
            return false
          }
          if (that.page == 1) {
            that.list = res.data.list
          } else {
            that.list = that.list.concat(res.data.list)
          }
          that.loading = false;
          that.page++
          //最后一次請求返回的數(shù)據(jù)為空或小于10條,不在請求,finished = true
          //根據(jù)業(yè)務(wù)需求更改
          if (res.data.list.length == 0 || res.data.list == null || res.data.list.length < 10) {
            that.finished = true
            return
          }
        })
      }
    }
  })
</script>
</html>

主要三個(gè)屬性

注意:

  • v-model 每次數(shù)據(jù)加載完成要置為false
  • finished 置為false后將不再觸發(fā)下拉加載
  • immediate-check 置為false后,每次進(jìn)入頁面將不會觸發(fā)load方法,防止進(jìn)入頁面多次加載

vant上拉加載更多,下拉刷新

1.html

? ?<van-pull-refresh v-model="isLoading" @refresh="onRefresh">
? ? ? ? ? ? <van-list
? ? ? ? ? ? ? v-model="loading"
? ? ? ? ? ? ? :finished="finished"
? ? ? ? ? ? ? :immediate-check="false"
? ? ? ? ? ? ? finished-text="沒有更多了呦"
? ? ? ? ? ? ? @load="onLoad"
? ? ? ? ? ? >?
? ? ? ? ?
? ? ? ? ? ? </van-list>
? ? ? ? ? </van-pull-refresh>

2.js

?return {? ??
? ? ? isLoading: false,
? ? ? loading: false,? ?
? ??
? ? ? page: 1,
? ? ? limit: 10,
? ? ? finished: false,
? ? ? total: 0, // 總共的數(shù)據(jù)條數(shù)
? ? ? List: [],?
? ? }
?
? ?getHistory() {
? ? ? const historyData = {
? ? ? ? page: this.page,
? ? ? ? limit: this.limit
? ? ? }
? ? ? return new Promise((resolve, reject) => {
? ? ? ? getHistory(historyData)
? ? ? ? ? .then(res => {
? ? ? ? ? ? if (res.code === 0) {
? ? ? ? ? ? ? console.log(res, '歷史記錄')
? ? ? ? ? ? ? this.total = res.data.total
? ? ? ? ? ? ? this.finished = !res.data.hasNext
? ? ? ? ? ? ? if (res.data.list && res.data.list.length > 0) {
? ? ? ? ? ? ? ? const tempList = res.data.list
? ? ? ? ? ? ? ? // console.log(this.page)
? ? ? ? ? ? ? ? if (this.page > 1) {
? ? ? ? ? ? ? ? ? this.list = this.list.concat(tempList)
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? this.list = tempList // 第一次加載
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.page += 1
? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? this.list = []
? ? ? ? ? ? ? }
? ? ? ? ? ? ? this.loading = false
? ? ? ? ? ? ? resolve()
? ? ? ? ? ? }
? ? ? ? ? })
? ? ? ? ? .catch(error => {
? ? ? ? ? ? reject(error)
? ? ? ? ? })
? ? ? })
? ? },?
?
? onLoad() {
? ? ? this.getHistory()
? ? },
? ? onRefresh() {
? ? ? this.page = 1
? ? ? setTimeout(() => {
? ? ? ? this.getHistory()
? ? ? ? Toast('刷新成功')
? ? ? ? this.isLoading = false
? ? ? }, 1000)
? ? },

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

相關(guān)文章

  • vue中實(shí)現(xiàn)回車鍵登錄功能

    vue中實(shí)現(xiàn)回車鍵登錄功能

    這篇文章主要介紹了vue中實(shí)現(xiàn)回車鍵登錄功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • vue3通過ref獲取子組件defineExpose的數(shù)據(jù)和方法

    vue3通過ref獲取子組件defineExpose的數(shù)據(jù)和方法

    defineExpose是Vue3中新增的選項(xiàng),用于向父組件暴露子組件內(nèi)部的屬性和方法,通過defineExpose,子組件可以主動控制哪些屬性和方法可以被父組件訪問,本文主要介紹了vue3通過ref獲取子組件defineExpose的數(shù)據(jù)和方法,需要的朋友可以參考下
    2023-10-10
  • vue-router后臺鑒權(quán)流程實(shí)現(xiàn)

    vue-router后臺鑒權(quán)流程實(shí)現(xiàn)

    本文主要介紹了vue-router后臺鑒權(quán)流程實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • vue mvvm數(shù)據(jù)響應(yīng)實(shí)現(xiàn)

    vue mvvm數(shù)據(jù)響應(yīng)實(shí)現(xiàn)

    這篇文章主要介紹了vue mvvm數(shù)據(jù)響應(yīng)實(shí)現(xiàn)的方法,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下
    2020-11-11
  • Vue項(xiàng)目中vue.config.js常用配置項(xiàng)詳解

    Vue項(xiàng)目中vue.config.js常用配置項(xiàng)詳解

    在 Vue CLI 創(chuàng)建的項(xiàng)目中,vue.config.js 是核心配置文件,用于定制化構(gòu)建、開發(fā)和部署流程,本文詳細(xì)解析了該文件的常用配置項(xiàng),并結(jié)合代碼示例和表格說明,幫助開發(fā)者高效管理項(xiàng)目配置,提升開發(fā)體驗(yàn),需要的朋友可以參考下
    2025-04-04
  • Vue項(xiàng)目中如何引入本地第三方JS庫

    Vue項(xiàng)目中如何引入本地第三方JS庫

    vue中常遇到第三方j(luò)s,這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中如何引入本地第三方JS庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • VSCode前端Vue項(xiàng)目引入Element-ui組件三步簡單操作方法

    VSCode前端Vue項(xiàng)目引入Element-ui組件三步簡單操作方法

    elementui相當(dāng)于一個(gè)庫,封裝好的內(nèi)容,我們引入到vue項(xiàng)目中,就可用庫中的內(nèi)容,這篇文章主要給大家介紹了關(guān)于VSCode前端Vue項(xiàng)目引入Element-ui組件的三步簡單操作方法,需要的朋友可以參考下
    2024-07-07
  • vue中button標(biāo)簽樣式和功能禁用的寫法

    vue中button標(biāo)簽樣式和功能禁用的寫法

    這篇文章主要介紹了vue中button標(biāo)簽樣式和功能禁用的寫法,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vue.js的計(jì)算屬性computed詳解

    Vue.js的計(jì)算屬性computed詳解

    文章介紹了Vue.js中的計(jì)算屬性(computed properties),解釋了它們的基本概念、語法、優(yōu)勢以及應(yīng)用場景,文章通過有趣的示例展示了計(jì)算屬性在不同場景下的應(yīng)用,如計(jì)算全名、計(jì)算列表的總和和計(jì)算對象的屬性,感興趣的朋友一起看看吧
    2025-03-03
  • VuePress 靜態(tài)網(wǎng)站生成方法步驟

    VuePress 靜態(tài)網(wǎng)站生成方法步驟

    這篇文章主要介紹了VuePress 靜態(tài)網(wǎng)站生成方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02

最新評論

珲春市| 乐昌市| 亳州市| 芒康县| 鄂托克旗| 浦城县| 光泽县| 江西省| 陇南市| 游戏| 河东区| 大荔县| 察雅县| 织金县| 涪陵区| 恩平市| 双辽市| 伊吾县| 色达县| 北安市| 彭水| 乐山市| 合肥市| 赤城县| 芒康县| 闵行区| 大足县| 泰来县| 博湖县| 炎陵县| 西乌珠穆沁旗| 辉县市| 垣曲县| 益阳市| 昭苏县| 新昌县| 岳阳市| 怀柔区| 通许县| 林甸县| 滕州市|