zoukankan      html  css  js  c++  java
  • vue下拉刷新,下拉加载更多

    首先下载插件better-scroll,命令:npm i better-scroll --save

    引入:import BScroll from "better-scroll";

    代码如下,效果图见文首:

    <template>
      <div>
        <div class="box"></div>
        <!-- ........... -->
        <div class="wrapper left" ref="wrapper">
          <div class="bscroll-container">
            <!-- 刷新提示信息 -->
            <div class="top-tip">
              <span class="refresh-hook">{{pulldownMsg}}</span>
            </div>
            <!-- 内容列表..........-->

            <ul class="content">
              <li v-for="item in data" :key="item" id="aaa">{{item}}</li>
            </ul>

            <!-- 底部提示信息........... -->
            <div class="bottom-tip">
              <span class="loading-hook">{{pullupMsg}}</span>
            </div>
          </div>
        </div>
        <!-- ............ -->
      </div>
    </template>

    <script>
    import BScroll from "better-scroll";
    // let count = 1;
    export default {
      name: "Z",
      data() {
        return {
          data: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
          pulldownMsg: "下拉刷新 ",
          pullupMsg: "加载更多 "
        };
      },
      mounted() {
        const that = this;
        // 创建Better-Scroll对象
        this.scroll = new BScroll(this.$refs.wrapper, {
          probeType: 1, //滚动的时候会派发scroll事件,会节流
          click: true //派发click事件
        });
        // //滑动结束松开事件
        this.scroll.on("touchEnd", pos => {
          //上拉刷新
          if (pos.y > 200) {
            setTimeout(() => {
              this.pulldownMsg = " ";
              this.scroll.refresh(); //重新计算高度
            }, 2000);
          } else if (pos.y < this.scroll.maxScrollY - 200) {
            this.pullupMsg = " ";
          }
        });
      }
    };
    </script>

    <style  scoped>
    .box {
       100%;
      height: 40px;
      background: #000;
    }
    .wrapper {
       20%;
      height: 500px;
      background: rgb(245, 247, 249);
      overflow: hidden;
      position: relative;
    }
    #aaa {
       100%;
      height: 50px;
      line-height: 50px;
      text-align: center;
    }
    /* 下拉、上拉提示信息 */
    .top-tip {
      position: absolute;
      top: -40px;
      left: 0;
      z-index: 1;
       100%;
      height: 40px;
      line-height: 40px;
      text-align: center;
      color: #555;
    }
    .bottom-tip {
       100%;
      height: 35px;
      line-height: 35px;
      text-align: center;
      color: #777;
      position: absolute;
      bottom: -35px;
      left: 0;
    }
    </style>
  • 相关阅读:
    [Selenium]Eclipse hangs at 57% in debug mode with TestNG tests
    [Selenium] CSS3 选择器
    [Selenium]如何实现上传本地文件
    [Selenium]显式等待 Explicit wait & 隐式等待 Implicit wait
    [Selenium]中使用css选择器进行元素定位
    [Selenium]验证点了某个Button之后无反应
    7. Debug on local machine
    6. Manage the driver for browser and the script for Hub
    4. Configure maven in Spring Tool Suite
    3. Install Spring-Tool-Suite & TestNG
  • 原文地址:https://www.cnblogs.com/bwnnxxx123/p/13405277.html
Copyright © 2011-2022 走看看