Article From:https://segmentfault.com/q/1010000008925195
Question:

WeChat official is a piece of shit, asking for 1 weeks, no reply.

page.wxml

<import src="../../common/template/template.wxml"/>

<block wx:if="{{ specials && !error }}">
<view class="page-product">
<scroll-view class="product-list" scroll-y="true" enable-back-to-top="true" bindscrolltolower="scrollLower" bindscroll="scroll" scroll-top="{{ scrollTop }}">
<template is="product-list" data="{{ products: specials }}"/>

<template is="loading" data="{{ hasMore: hasMore }}"/>
</scroll-view>
</view>
</block>

<block wx:else>

<template is="error" data="{{ errMsg: error }}"/>
</block>

page.js

var app = getApp();

Page({
  data:{
    page: 1,
    scrollTop: 0,
    hasMore: true,
    specials: [],
    error: null
  },
  onLoad:function(options){
        this.getSpecial()
        console.log(1);
  },
  scrollLower: function() {
        this.getSpecial()
        console.log(2);
  },
  scroll: function(e) {
        let sTop = e.detail.scrollTop;
        this.setData({
            scrollTop: sTop
        });
  }
  getSpecial: function() {
        let page = this.data.page
        let rows = this.data.specials
        if(page == 0) {
            return
        }
        app.common.request('product/discount',{ page: page, size: 20},(ret) => {
            if(ret.err_no == 0) {

                for(var x in ret.results.rows) {

                    rows.push(ret.results.rows[x]);
                }

               let nextPage = (ret.results.next == page ? 0 : ret.results.next);

               this.setData({
                  page: nextPage,
                  hasMore: (nextPage == 0 ? false : true),
                  specials: rows
               });

            } else {

                this.setData({
                    error: ret.err_msg
                })
            }
        })
    },
})

The scrollLower () above will be executed several times.

page.json

{
    "navigationBarTitleText": "The bazaar ","EnablePullDownRefresh": false}

template.wxml

<template name="product-list">
<view class="list-item" wx:for="{{ products }}" wx:for-item="item" wx:key="{{ item.id }}">
    <navigator url="/pages/product/detail?id={{ item.id }}" open-type="navigate">
    <image class="list-item__image" src="{{ item.thumb }}" mode="aspectFill"></image>
    <view class="list-item__desc">
        <text class="list-item__title">{{ item.name }}</text>
        <text class="list-item__cate">{{ item.category }}</text>
        <text class="list-item__price">{{ item.price == 0 ? 'Bargaining price: '+' + (item.price_discount = = 0: item.price: item.price_discount)}}< /text>&lT; /view>< /navigator>< /view>< /template>< template name= "loading" >< view class= "loading" >< block wx:if= "wx:if= (hasMore))" >< view class= "loading-image">< text> life loading... < /text>< /view>< /block>< block wx:else>< view class= "loading-text" >< text> I'm the bottom line < /text>< /view></block>< /view>< /template>< template name= "error" >< view class= "error" >< icon type= "warn" size= "120" color= "#ccc" > < /icon>< text> errMsg}}< /text>< /view>< /template>

Pull-down will shake, scrollLower () will be asked several times!

Answer 0:

Set a switch variable, such as: isFreshing, the default setting of isFreshing: false, when calling the interface to get the data to determine whether isFreshing is true, if it is, return is good, if not, execute the request.And then set it to true, get the data, and then set it to false.

Answer 1:

I have encountered the same problem. Has the landlord solved it?

Answer 2:

Setting up lower-threshold=1

Answer 3:

That’s what I did.
wxml Set up the function named {{loadMore}}
data The initial value is loadMore: “loadMore”
When the loadMore function is triggered, the value of SetData loadMore is empty or other.
Finally, reset the value of loadMore back to “loadMore” at the end of loading.

Answer 4:

@_JustCk …

Leave a Reply

Your email address will not be published. Required fields are marked *