日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

下拉刷新和上拉加载 php,怎样操作vue2.0 移动端实现下拉刷新和上拉加载

發布時間:2023/12/29 php 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 下拉刷新和上拉加载 php,怎样操作vue2.0 移动端实现下拉刷新和上拉加载 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這次給大家帶來怎樣操作vue2.0 移動端實現下拉刷新和上拉加載,操作vue2.0 移動端實現下拉刷新和上拉加載的注意事項有哪些,下面就是實戰案例,一起來看一下。

直接上代碼,不懂的多看幾遍,下面我換會告訴大家如何使用。

:class="{'down':(state===0),'up':(state==1),refresh:(state===2),touch:touching}"

@touchstart="touchStart($event)"

@touchmove="touchMove($event)"

@touchend="touchEnd($event)"

@scroll="(onInfinite || infiniteLoading) ? onScroll($event) : undefined">

下拉更新

松開更新

更新中

加載中……

export default {

props: {

offset: {

type: Number,

default: 40

},

enableInfinite: {

type: Boolean,

default: true

},

enableRefresh: {

type: Boolean,

default: true

},

onRefresh: {

type: Function,

default: undefined,

required: false

},

onInfinite: {

type: Function,

default: undefined,

require: false

}

},

data() {

return {

top: 0,

state: 0,

startY: 0,

touching: false,

infiniteLoading: false

}

},

methods: {

touchStart(e) {

this.startY = e.targetTouches[0].pageY

this.startScroll = this.$el.scrollTop || 0

this.touching = true

},

touchMove(e) {

if (!this.enableRefresh || this.$el.scrollTop > 0 || !this.touching) {

return

}

let diff = e.targetTouches[0].pageY - this.startY - this.startScroll

if (diff > 0) e.preventDefault()

this.top = Math.pow(diff, 0.8) + (this.state === 2 ? this.offset : 0)

if (this.state === 2) { // in refreshing

return

}

if (this.top >= this.offset) {

this.state = 1

} else {

this.state = 0

}

},

touchEnd(e) {

if (!this.enableRefresh) return

this.touching = false

if (this.state === 2) { // in refreshing

this.state = 2

this.top = this.offset

return

}

if (this.top >= this.offset) { // do refresh

this.refresh()

} else { // cancel refresh

this.state = 0

this.top = 0

}

},

refresh() {

this.state = 2

this.top = this.offset

this.onRefresh(this.refreshDone)

},

refreshDone() {

this.state = 0

this.top = 0

},

infinite() {

this.infiniteLoading = true

this.onInfinite(this.infiniteDone)

},

infiniteDone() {

this.infiniteLoading = false

},

onScroll(e) {

if (!this.enableInfinite || this.infiniteLoading) {

return

}

let outerHeight = this.$el.clientHeight

let innerHeight = this.$el.querySelector('.inner').clientHeight

let scrollTop = this.$el.scrollTop

let ptrHeight = this.onRefresh ? this.$el.querySelector('.pull-refresh').clientHeight : 0

let infiniteHeight = this.$el.querySelector('.load-more').clientHeight

let bottom = innerHeight - outerHeight - scrollTop - ptrHeight

if (bottom < infiniteHeight) this.infinite()

}

}

}

.yo-scroll {

position: absolute;

top: 2.5rem;

right: 0;

bottom: 0;

left: 0;

overflow: auto;

-webkit-overflow-scrolling: touch;

background-color: #ddd

}

.yo-scroll .inner {

position: absolute;

top: -2rem;

width: 100%;

transition-duration: 300ms;

}

.yo-scroll .pull-refresh {

position: relative;

left: 0;

top: 0;

width: 100%;

height: 2rem;

display: flex;

align-items: center;

justify-content: center;

}

.yo-scroll.touch .inner {

transition-duration: 0ms;

}

.yo-scroll.down .down-tip {

display: block;

}

.yo-scroll.up .up-tip {

display: block;

}

.yo-scroll.refresh .refresh-tip {

display: block;

}

.yo-scroll .down-tip,

.yo-scroll .refresh-tip,

.yo-scroll .up-tip {

display: none;

}

.yo-scroll .load-more {

height: 3rem;

display: flex;

align-items: center;

justify-content: center;

}

把上面組件拷貝一下,存成后綴是.vue的組件放到你的component下, 然后引入到頁面 , 下面是我引用的demo

上代碼: 里面有注釋哦,有問題給我留言!

  • {{item.name}}
  • {{item.name}}

import Scroll from './y-scroll/scroll';

export default{

data () {

return {

counter : 1, //默認已經顯示出15條數據 count等于一是讓從16條開始加載

num : 15, // 一次顯示多少條

pageStart : 0, // 開始頁數

pageEnd : 0, // 結束頁數

listdata: [], // 下拉更新數據存放數組

downdata: [] // 上拉更多的數據存放數組

}

},

mounted : function(){

this.getList();

},

methods: {

getList(){

let vm = this;

vm.$http.get('https://api.github.com/repos/typecho-fans/plugins/contents/').then((response) => {

vm.listdata = response.data.slice(0,15);

}, (response) => {

console.log('error');

});

},

onRefresh(done) {

this.getList();

done() // call done

},

onInfinite(done) {

let vm = this;

vm.$http.get('https://api.github.com/repos/typecho-fans/plugins/contents/').then((response) => {

vm.counter++;

vm.pageEnd = vm.num * vm.counter;

vm.pageStart = vm.pageEnd - vm.num;

let arr = response.data;

let i = vm.pageStart;

let end = vm.pageEnd;

for(; i

let obj ={};

obj["name"] = arr[i].name;

vm.downdata.push(obj);

if((i + 1) >= response.data.length){

this.$el.querySelector('.load-more').style.display = 'none';

return;

}

}

done() // call done

}, (response) => {

console.log('error');

});

}

},

components : {

'v-scroll': Scroll

}

}

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

總結

以上是生活随笔為你收集整理的下拉刷新和上拉加载 php,怎样操作vue2.0 移动端实现下拉刷新和上拉加载的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。