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

如何封裝了一個(gè)vue移動(dòng)端下拉加載下一頁(yè)數(shù)據(jù)的組件

 更新時(shí)間:2019年01月06日 17:09:08   作者:Haorooms  
這篇文章主要介紹了如何封裝了一個(gè)vue移動(dòng)端下拉加載下一頁(yè)數(shù)據(jù)的組件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

前言

簡(jiǎn)單封裝了一個(gè)vue下拉加載組件,分享一下,已放到github和前端資源庫(kù),歡迎下載!

組件代碼

<template>
 <div class="my-scroll" :class="[scrollState?'prohibit':'allow']" ref="myScroll" @scroll.passive="onScroll($event)" @touchmove="onScroll($event)" >
  <!-- top -->
  <div class="scroll-list">
   <slot name='scrollList'></slot>
   <div class="scroll-bottom">
    <div v-if="state==1">
     <i><img :src="Load"/></i>
     <p>加載中</p>
     </div>
    <div v-if="state==2">加載完成</div>
    <div v-if="state==3">沒(méi)有數(shù)據(jù)了</div>
   </div>
  </div>
 </div>
</template>
<script type="text/javascript">
import Load from '@/assets/Load.gif'
export default {
 name: 'myScroll',
 props: {
 'onPull': { // 加載回調(diào)
  type: Function,
  require: true
 },
 'scrollState': {// 是否可滑動(dòng)
  type: Boolean,
  require: true
 },
 loaded: {
  type: Boolean,
  default() {
  return false
  }
 }
 },
 data() {
 return {
  Load,
  timeoutId: null,
  state: 0,
  myScroll: null
 }
 },
 methods: {
 /*
    * 加載中:1
    * 加載完成:2
    * 沒(méi)有更多:3
    */
 setState(index) { // 修改狀態(tài)
  this.state = index
  // console.log(this.state)
 },
 onScroll(e) {
  const _this = this
  const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
  // console.log(window.innerHeight + scrollTop, this.myScroll.offsetHeight)
  if (!this.loaded && window.innerHeight + scrollTop - 50 >= this.myScroll.offsetHeight) {
  clearTimeout(this.timeoutId)
  _this.timeoutId = setTimeout(() => {
   _this.bottomCallback()
  }, 100)
  }
 },
 bottomCallback() { // 加載回調(diào)
  // console.log('回調(diào)', new Date().getTime())
  if (this.state != 3) {
  this.state = 1
  this.onPull()
  }
 }
 },
 mounted() {
 this.myScroll = this.$refs.myScroll // 獲取滑條dom
 }
}
</script>
<style lang="scss" scoped>
 .allow{
  overflow:hidden;
  height: auto;
 }
 .prohibit{
  max-width: 100%;
  max-height: 100%;
  height: 100%;
  overflow:hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  will-change: transform;
  transition: all 450ms;
  backface-visibility: hidden;
  perspective: 1000;
 }
 .my-scroll{
  position: relative;
   color: #999;
  .scroll-top{
   text-align: center;
   display:flex;
   position:absolute;
   top:0;
   left:0;
    width:100%;
    overflow: hidden;
  }
  .scroll-list{
   overflow:hidden;
   min-height: 100%;
  }
  .scroll-bottom{
   text-align: center;
   line-height: .8rem;
  div{
    display:flex;
     height:auto;
    width:100%;
    justify-content: center;
    align-items:center;
    flex-wrap: wrap;
    i{
     flex:1 0 100%;
     display:block;
     height: 0.4rem;
    }
    img{
     width:0.6rem;
    }
    p{
     flex:1 0 100%;
    }
   }
  }
 }
</style>

使用

<template>
 <div id="app">
  <my-scroll class="scrolls" ref="myScroll" :on-pull="getList" :loaded="loaded" :scroll-state="scrollState">
   <div slot="scrollList">
   <div class="list" v-for="(item,index) in listData" :key="index">{{item.name}}</div>
   </div>
  </my-scroll>
 </div>
</template>
<script>
import myScroll from "./components/vue-scroll.vue";
import axios from 'axios'
export default {
 name: "app",
 data(){
 return{
  scrollState: true, // 是否可以滑動(dòng)
  loaded: false,
  iPage: 1,
  listData:[],
  iPageSize: 10,
 }
 },
 methods: {
 getList(){
  this.$refs.myScroll.setState(1)
  let _this = this
  // ajax 請(qǐng)求
  axios.get('https://easy-mock.com/mock/5b90f971ce624c454133ee2d/scoll/datalist').then(function (response) {
   if (response.data.code == 200 && response.data.data.pagelist.length > 0 && !_this.loaded) {
    if (_this.iPage == 1) {
    _this.listData = response.data.data.pagelist
    } else {
    _this.listData.push(...response.data.data.pagelist)
    }
    _this.iPage++
    _this.$refs.myScroll.setState(2)
   } else {
    if (_this.iPage == 1) {
    _this.czListData = []
    }
    _this.loaded = true
    _this.$refs.myScroll.setState(3)
   } 
   })
   .catch(function (error) {
   console.log(error);
   });
  }

 },
 mounted () {
 this.getList() 
 },
 components: {
 myScroll
 }
};
</script>

<style scoped>
#app {
 font-family: "Avenir", Helvetica, Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
}
.scrolls{
 font-size:.24rem;
}
.list{
 height:.9rem;
 line-height: .9rem;
 margin-bottom:.1rem;
 border-bottom:1px solid #dedede;
 color:#999;
 font-size:.28rem;
}
</style>

組件已放到github,歡迎下載和star

可以直接在vue項(xiàng)目中運(yùn)行這個(gè)組件

github地址:https://github.com/confidence68/vue_mobile_scrollLoadpage

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vuex的核心概念和基本使用詳解

    vuex的核心概念和基本使用詳解

    這篇文章主要為大家介紹了vuex的核心概念和基本使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-12-12
  • Element中el-table動(dòng)態(tài)合并單元格(span-method方法)

    Element中el-table動(dòng)態(tài)合并單元格(span-method方法)

    本文主要介紹了Element中el-table動(dòng)態(tài)合并單元格(span-method方法),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • vue獲取el-form的整體驗(yàn)證狀態(tài)

    vue獲取el-form的整體驗(yàn)證狀態(tài)

    本文主要介紹了vue獲取el-form的整體驗(yàn)證狀態(tài),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • vue下使用nginx刷新頁(yè)面404的問(wèn)題解決

    vue下使用nginx刷新頁(yè)面404的問(wèn)題解決

    這篇文章主要介紹了vue下使用nginx刷新頁(yè)面404的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • VueJs路由跳轉(zhuǎn)——vue-router的使用詳解

    VueJs路由跳轉(zhuǎn)——vue-router的使用詳解

    本篇文章主要介紹了VueJs路由跳轉(zhuǎn)——vue-router的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-01-01
  • vue項(xiàng)目基于WebRTC實(shí)現(xiàn)一對(duì)一音視頻通話(huà)

    vue項(xiàng)目基于WebRTC實(shí)現(xiàn)一對(duì)一音視頻通話(huà)

    這篇文章主要介紹了vue項(xiàng)目基于WebRTC實(shí)現(xiàn)一對(duì)一音視頻通話(huà)效果,實(shí)現(xiàn)代碼分為前端和后端兩部分代碼,需要的朋友可以參考下
    2024-05-05
  • vue3.x源碼剖析之?dāng)?shù)據(jù)響應(yīng)式的深入講解

    vue3.x源碼剖析之?dāng)?shù)據(jù)響應(yīng)式的深入講解

    這篇文章主要給大家介紹了關(guān)于vue3.x源碼剖析之?dāng)?shù)據(jù)響應(yīng)式的相關(guān)資料,在講解過(guò)程中,我們會(huì)對(duì)比Vue2.x的API特性,使用有哪些區(qū)別,需要的朋友可以參考下
    2022-01-01
  • 前端Vue頁(yè)面中展示本地圖片簡(jiǎn)單代碼示例

    前端Vue頁(yè)面中展示本地圖片簡(jiǎn)單代碼示例

    今天遇到一個(gè)在vue文件中引入本地圖片的問(wèn)題,于是有了這篇文章,本文主要給大家介紹了關(guān)于前端Vue頁(yè)面中展示本地圖片的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • 如何使用Vue3+Vite+TS快速搭建一套實(shí)用的腳手架

    如何使用Vue3+Vite+TS快速搭建一套實(shí)用的腳手架

    Vite是一個(gè)面向現(xiàn)代瀏覽器的一個(gè)更輕、更快的?Web?應(yīng)用開(kāi)發(fā)工具,下面這篇文章主要給大家介紹了關(guān)于如何使用Vue3+Vite+TS快速搭建一套實(shí)用腳手架的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • python虛擬環(huán)境 virtualenv的簡(jiǎn)單使用

    python虛擬環(huán)境 virtualenv的簡(jiǎn)單使用

    virtualenv是一個(gè)創(chuàng)建隔絕的Python環(huán)境的工具。這篇文章主要介紹了python虛擬環(huán)境 virtualenv的簡(jiǎn)單使用,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-01-01

最新評(píng)論

壶关县| 方山县| 隆林| 广灵县| 海南省| 上虞市| 涪陵区| 轮台县| 厦门市| 红原县| 闻喜县| 陈巴尔虎旗| 满洲里市| 嘉峪关市| 富顺县| 新乡市| 南皮县| 静宁县| 阳朔县| 松江区| 濮阳县| 黔江区| 永胜县| 河南省| 许昌县| 青阳县| 胶南市| 老河口市| 邮箱| 弋阳县| 多伦县| 新巴尔虎右旗| 葵青区| 平乡县| 景德镇市| 云霄县| 南部县| 乐业县| 秭归县| 亳州市| 湟中县|