请求滚动两次

时间:2020-01-29 06:30:09

标签: javascript vue.js

我正在使用VueJs开发网站,并且已将JQuery用于滚动功能。

当用户滚动到页面底部时,我正在递增页面编号。 首先(页面= 1),它仅显示一个请求。 但是,当向下滚动时,会同时触发两个请求(页面= 2,页面= 3)。

getDisplay()函数用于获取数据,我为此设置了LIMITOFFSET值。

        mounted: function() {
        this.getDisplay();
        this.bindScroll();
    },
    methods: {
        bindScroll: function(){
            var vm = this;
            $(window).bind('scroll', function () {
                if ($(window).scrollTop() === $(document).height() - $(window).height()) {
                    if(vm.isMorePost > 0){
                        vm.showLoading = 1;
                        vm.page++;
                        vm.getDisplay();
                    }
                }
            })
        },
        getDisplay: function() {

            var input = {
                name: this.userId,
                recordPerPage: this.recordPerPage,
                page: this.page
            };

            this.loadingIcon = 1;
            this.$http.get('/display-view/show/get-user-display', {params: input}).then(function(response) {
                this.display = this.display.concat(response.data.data);
                this.isMorePost = (response.data.data.length);
                if(response.data.data.length == 0){
                    this.showLoading = 0
                }else {
                    this.showLoading = 1
                }
            }.bind(this));

        }
    },

当用户遇到页面底部时,我只需要触发一个页面增加的请求。我该如何解决?

0 个答案:

没有答案