애플릿은 위로 당기고 더 많이 불러오기를 실현한다

1919 단어 애플릿
사고방식: 위로 더 많이 불러오기(페이지에서 밑에 닿는 이벤트)는 새로 얻은 데이터를 데이터의 원시 데이터에 추가하는 것이다.
const app = getApp();
Page({
    data: {
        movieList: [],
        page: 1// , 
    },
    onLoad() {
        var that = this;
        this.getMore(that.data.page);
    },
    onReachBottom: function() {
        console.log(1);
        swan.showLoading({
            title: ' ',
            make: true
        })
        var that = this;
        this. getMore(that.data.page);
    
    },
    getMore: function (page) {
        var that = this;
        if (page == 1) {
            swan.showLoading({
                title: '  ',
                make: true
            })
        }
        swan.request({
            url: 'https://mip.yesky.com/fishVideo/video/movieList.json',
            method: 'GET',
            data: {
                pageNo: page
            },
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                var res = res.data.movieList;
                if (that.data.page > 1) {
                    var movieLists = that.data.movieList;
                    console.log(movieLists);
                    that.setData({
                        movieList: movieLists.concat(res),
                        page: page + 1
                    })
                } else {
                    that.setData({
                        movieList: res,
                        page: page + 1
                    })
                }
            }, fail: function () {
                swan.showToast({
                    title: ' ',
                    duration: 1500
                })
            },
            complete: function () {
                if (page >= 1) {
                    swan.hideLoading()
                }
            }
        })
    }

})

좋은 웹페이지 즐겨찾기