• 如何使用uview中的loadmore上拉加载


    普通用法

    HTML 

    1. <view>
    2. <view>
    3. view>
    4. <u-loadmore :status="status" />
    5. view>

    JS,onReachBottom这个是生命周期,和method同级

    1. data() {
    2. return {
    3. goods:null,
    4. status: 'loadmore',//当前状态
    5. pageSize: 20,//获取多少条数据
    6. pageNum: 1//当前页码
    7. }
    8. }
    9. onReachBottom() {
    10. let that= this;
    11. that.status = 'loading';
    12. that.pageNum = ++ that.pageNum;
    13. setTimeout(() => {
    14. that.goods_list()
    15. }, 600);
    16. },
    17. methods: {
    18. goods_list() {
    19. let that = this
    20. //写上自己的接口
    21. that.$http.https("GET", "/index/broadcast/broadcast_goods", {
    22. 'pageSize': that.pageSize,
    23. 'pageNum': that.pageNum
    24. }).then(req => {
    25. if (req.data.code == 200) {
    26. //页面是1先重置
    27. if (that.pageNum === 1) {
    28. that.goods = null
    29. }
    30. //追加数据
    31. req.data.goods.forEach(data => {
    32. that.goods.push(data)
    33. })
    34. //是否最后一页
    35. if (req.data.goods.length < that.pageSize) {
    36. that.status = 'nomore';
    37. } else {
    38. that.status = 'loadmore';
    39. }
    40. } else {
    41. that.goods = null
    42. that.status = 'nomore';
    43. }
    44. }
    45. }
    46. }

    如果是弹窗的要用loadmore事件

    HTML ,利用@touchmove.native.stop.prevent 阻止穿透

    1. <view>
    2. <u-popup :closeOnClickOverlay="true" closeIconPos="top-right" round="20" :show="goods_show" mode="bottom" @close="close" @open="open" @touchmove.native.stop.prevent>//@touchmove.native.stop.prevent 阻止穿透
    3. <view>
    4. view>
    5. <u-loadmore :status="status" @loadmore='loading' :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
    6. u-popup>
    7. view>

    JS,不再采用onReachBottom这个生命周期

    1. data() {
    2. return {
    3. goods_show: false,
    4. goods: null,
    5. loadingText: '努力加载中...',
    6. loadmoreText: '点我加载更多',
    7. nomoreText: '宝宝底线啦',
    8. status: 'loadmore',
    9. pageSize: 20,
    10. pageNum: 1
    11. }
    12. }
    13. methods: {
    14. //打开时
    15. open() {
    16. let that = this
    17. that.pageNum = 1
    18. that.goods_list()
    19. },
    20. loading() {
    21. let that = this
    22. that.status = 'loading';
    23. that.pageNum = ++that.pageNum;
    24. setTimeout(() => {
    25. that.goods_list()
    26. }, 300)
    27. },
    28. goods_list() {
    29. let that = this
    30. //写上自己的接口
    31. that.$http.https("GET", "/index/broadcast/broadcast_goods", {
    32. 'pageSize': that.pageSize,
    33. 'pageNum': that.pageNum
    34. }).then(req => {
    35. if (req.data.code == 200) {
    36. //页面是1先重置
    37. if (that.pageNum === 1) {
    38. that.goods = null
    39. }
    40. //追加数据
    41. req.data.goods.forEach(data => {
    42. that.goods.push(data)
    43. })
    44. //是否最后一页
    45. if (req.data.goods.length < that.pageSize) {
    46. that.status = 'nomore';
    47. } else {
    48. that.status = 'loadmore';
    49. }
    50. } else {
    51. that.goods = null
    52. that.status = 'nomore';
    53. }
    54. }
    55. },
    56. //关闭时
    57. close() {
    58. let that = this;
    59. that.goods_show = false;
    60. that.goods = null;
    61. }
    62. }

    后端tp6

    1. public function broadcast_goods(Request $request)
    2. {
    3. $data = $request->get();
    4. $pagenum = ($data["pageNum"] - 1) * 20;//当前页
    5. $pagesize = $data["pageSize"];
    6. $goods = Db::query("select * from dq_goods where goods_state=1 and delete_time=0 order by goods_sort limit $pagenum,$pagesize");
    7. if (!empty($goods)){
    8. return json(['code' => 200, 'goods' => $goods, 'msg' => '查询成功']);
    9. }else{
    10. return json(['code' => 201, 'msg' => '操作成功']);
    11. }
    12. }

  • 相关阅读:
    9.8 校招 实习 内推 面经
    自学Java的初学者,如何开始?
    F#奇妙游(32):缺失数据集合的处理
    无法将类型为“Newtonsoft.Json.Linq.JObject”的对象转换为类型“Newtonsoft.Json.Linq.JArray”解决方法
    从 SAN 到 SDS,XSKY 持续助力中英人寿存储架构革新
    进程调度算法
    零基础学python之数据类型
    java 新特性之 Stream API
    大数据学习之分布式数据采集系统Flume学习
    【深度学习】实验1布置:Softmax实现手写数字识别
  • 原文地址:https://blog.csdn.net/weixin_43453621/article/details/133910009