vue横屏分页加载 vue 分页 左右滑动分页 横着分页

vue 分页 加载 vue横屏分页加载
关键词:横着分页,左右分页,横屏分页,左右滑动分页
请添加图片描述

b站视频地址:https://b23.tv/sEYwH5

切记一定要把public/index.html 里面的body设置margin、padding 为0,不然可能会出问题


<template>
  <div class="hello">
    <div class="list" id="tablist" @scroll="listScroll">
      <div
        class="item"
        v-for="(item, i) in datas"
        :key="i"
        :class="i % 2 == 0 ? 'red' : 'skyblue'"
      >
        {{ item }}
      </div>
      <div v-if="loading" class="loading">loading...</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  data() {
    return {
      flag: true, // 开关
      loading: false, // loading加载
      datas: [1, 2, 3, 4, 5, 6], // 列表数据
    };
  },
  methods: {
    listScroll() {
      const scrollLeft = document.getElementById("tablist").scrollLeft;
      console.log("卷去宽度", scrollLeft);
      const clientWidth = document.documentElement.clientWidth || document.body.clientWidth;
      console.log("屏幕宽度", clientWidth);
      const tablist = document.getElementById("tablist").scrollWidth;
      console.log("列表宽度", tablist);
      console.log("-----------");
      if (tablist - clientWidth === scrollLeft && this.flag) {
        // 列表宽度-屏幕宽度 = 卷曲宽度  且  开关是打开的状态
        console.log("滑不动了");
        this.pageFn(); // 模拟 请求数据
      }
    },
    pageFn() {
      console.log("去分页请求**********");
      this.flag = false; // 开关 关闭
      this.loading = true; // loading 打开
      const that = this;

      // 模拟延迟请求
      setTimeout(() => {
        that.reqFn(); // 接口请求数据
      }, 1500);
    },
    reqFn() {

      const num = this.datas.length + 1; // 模拟新数据
      this.datas.push(num); // 新数据赋值
      this.flag = true; // 开关 打开
      this.loading = false; // loading 关闭
    },
  },
};
</script>


<style scoped>
.list {
  width: 100vw;
  height: 100px;
  overflow-x: scroll;
  white-space: nowrap;
}
.item {
  display: inline-block;
  width: 100px;
  height: 100px;
  box-sizing: content-box;
  line-height: 100px;
}
.red {
  background-color: red;
}
.skyblue {
  background-color: skyblue;
}
.loading {
  width: 80px;
  height: 100px;
  line-height: 100px;
  background: rgba(0, 0, 255, 0.664);
  display: inline-block;
}
</style>



<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
/* h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
} */
</style>

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

前端酱紫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值