vue+vant 实现上拉加载 下拉刷新

先上js

// 页面首次加载数据列表
    getlist() {
      this.loading = true;
      this.apiGet("/order/order_list", {
        params: {
          order_status: Number(this.order_status),
          page: this.pagenum
        }
      }).then(res => {
        this.loading = false; // 加载状态结束
        this.total = res.data.count;
        this.list=this.list.concat(res.data.data)
        console.log('*页面首次加载数据列表*',this.list);
        this.refreshing = false;
        this.pagenum += 1;
      });
    },
    // 下拉刷新
    onRefresh() {
      console.log('触发下拉刷新');
      setTimeout(()=>{
      if(this.refreshing ){
          this.list = this.list;
          this.refreshing = false;
      }
       this.loading = false;
      },1000)
    },
    // 上拉加载
    onLoad() {
      console.log('触发上拉加载');
      this.loading = true;
      setTimeout(() => {
         this.order_status= 1;
      if(this.list.length<this.total ){
        this.getlist();
        this.loading = false;
      }else{
        this.loading = false;
        this.finished = true;
      }
      }, 1000);
    },

Html

      <van-tab title="全部订单" name="null">
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
          <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <van-cell v-for="(item , index ) in list" :key="index">
              <van-row type="flex" justify="space-between" class="box">
                <van-col span="9" style="margin-right:15px;height:70%" @click="active">
                  <van-image :src="item.activity_img" style="height: 100%;"></van-image>
                </van-col>
                <van-col span="16" class="right">
                  <div @click="details(item.order_id)">
                    <div style="flex-direction: column; justify-content: space-between;">
                      <h5>{{item.body}}</h5>
                      <div style="float: right;">
                        <span>{{item.price}}</span>
                        <span style="display:flex; margin-top:-10px;margin-left:40px">x{{item.sum}}</span>
                      </div>
                    </div>
                    <div>
                      <span>活动时间</span>
                      <h6>{{item.use_end_time | formatTime }}</h6>
                      <h6>{{item.use_start_time | formatTime}}</h6>
                    </div>
                    <div class="address">
                      <span
                        style="font-size: 10px"
                      >{{item.county_name}}{{item.address}}{{item.county_name}}{{item.address}}</span>
                    </div>
                    <div
                      style="margin-top:-6px;display:flex;float:right;font-size: 11px;"
                    >总价¥{{item.total_fee}}</div>
                  </div>
                  <div style="margin-top:10px">
                    <div class="btn" style="float:left" @click="refunds(item.order_id)">
                      <span>退款</span>
                    </div>
                    <div class="btn" style="margin-left:60px" @click="code">
                      <span>二维码</span>
                    </div>
                  </div>
                </van-col>
              </van-row>
            </van-cell>
          </van-list>
        </van-pull-refresh>
      </van-tab>

data数据

import IsEmpty from "@/components/include/empty/";
import { Toast } from "vant";
import { formatDateTime } from "../utils/date";
export default {

  data() {
    return {
      // 图
      fang: require("../assets/qita/fang.png"),
      // 视频图片
      // sp:require("../assets/qita/img.png"),
      order_status: 1, //标签默认
      pagenum: 1, //当前页数
      total: null, //总条数
      list: [],
      order_id: "", //活动id
      loading: false, //是否处于加载状态
      finished: false, //是否已加载完成
      refreshing: false //加载完成后的提示文案
    };
  },

时间转换

  // 时间转化
  filters: {
    formatTime(time) {
      if (time == null || time === "") {
        return "N/A";
      }
      return formatDateTime(time, "yyyy-MM-dd hh:mm:ss");
    }
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq614756883

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值