基于vue封裝的輕量級下拉刷新組件

Github地址:vpull-refresh

如何使用

將項目中的src/components/pullRefresh.vuesrc/img拷貝到你的工程內(nèi)。如層級發(fā)生改變,你需要手動修改pullRefresh.vue中的圖片鏈接地址。

API

屬性 說明 類型 默認(rèn)值
refreshing 是否處于刷新狀態(tài) boolean false
onRefresh 刷新的回調(diào)函數(shù) function () => {}
tipHeight 刷新提示信息的高度 string 50px
pullHeight 滾動區(qū)域高度 string 100vh
pullTip 下拉時的提示文字 string 下拉即可刷新
refreshTip 刷新中的提示文字 string 正在刷新

示例

<template>
<pull-refresh :refreshing="isRefreshing" :on-refresh="onRefresh" pull-height="400px">
  <div class="list">
    <p v-for="n in 20">{{n}}</p>
  </div>
</pull-refresh>
</template>

<script>
import pullRefresh from "@/components/pullRefresh.vue";
  export default  {
    name: 'Example',
    data() {
      return {
        isRefreshing: false
      }
    },
    methods: {
      onRefresh() {
        //刷新前需要先手動將設(shè)為true,否則pull-refresh不會監(jiān)測到狀態(tài)變化
        this.isRefreshing = true;
        setTimeout(() => {
          this.isRefreshing = false;
        }, 5000)
      }
    },
    components: { pullRefresh }
}
</script>

<style scoped>
.list {
  background-color: white;
}
p {
  margin: 0;
}
</style>

手動刷新

<pull-refresh :refreshing="isRefreshing">
  <div class="list">
    <p v-for="n in 20">{{n}}</p>
    <button @tap="refresh">手動刷新</button>
  </div>
</pull-refresh>

<script>
//在methods中添加如下代碼
tap() {
  this.isRefreshing = true;
  setTimeout(() => {
    this.isRefreshing = false;
  }, 5000)
}
</script>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容