首页 > 其他分享 >vue3 监听容器滚动到底部

vue3 监听容器滚动到底部

时间:2023-08-25 15:13:19浏览次数:42  
标签:容器 const target bottom clientHeight vue3 scrollTop 监听 scrollHeight

在容器里面添加@scroll事件

<template>
  <div @scroll="scrolling" id="content">
    <p v-for="i in Array.from({length: 30}, (v, i) => i)">
      {{ i }}
    </p>
  </div>
  <div v-if="bottom">到达底部</div>
</template>

<script setup>
  import { ref } from 'vue'
   
  const bottom = ref(false)
   
  const scrolling = (e) => {
    const clientHeight = e.target.clientHeight
    const scrollHeight = e.target.scrollHeight
    const scrollTop = e.target.scrollTop
     
    if (scrollTop + clientHeight >= scrollHeight) {
      console.log('到底了!')
      bottom.value = true
    } else {
      bottom.value = false
    }
  }
</script>

<style>  
  #content {
    height: 200px; 
    overflow: auto; 
    border: 1px solid red; 
    padding: 0 10px;
  }
</style>

标签:容器,const,target,bottom,clientHeight,vue3,scrollTop,监听,scrollHeight
From: https://www.cnblogs.com/elaina520/p/17656987.html

相关文章

  • Redis开启过期监听
    1.开启过期通知配置默认notify-keyspace-events""修改为:notify-keyspace-eventsEx2.增加监听类publicclassRedisKeyExpirationListenerextendsKeyExpirationEventMessageListener{publicRedisKeyExpirationListener(RedisMessageListenerContainerlisten......
  • 容器 时区
    FROM*.*.com//centos7:v3#将编译生成的jar包拷贝到镜像中COPY./git-resource/purchase-api/target/*.jar/api.jarCOPY./config/run.sh/run.sh#时区ENVTZAsia/ShanghaiRUNln-fs/usr/share/zoneinfo/${TZ}/etc/localtime\&&echo${TZ}>/etc/timezone......
  • 过滤器| 拦截器| 监听器的区别与使用
    骑士李四记录:1.过滤器(Filter):过滤器依赖于servlet容器。在实现上基于函数回调。几乎可以对所有请求进行过滤。缺点是一个过滤器实例只能在容器初始化时调用一次。2.拦截器(Interceptor)拦截器依赖于web框架,在SpringMVC中依赖于SpringMVC框架。实现上基于java反射机制,属于面向切......
  • Vue3内置组件suspense用法
    1、作用在使用异步组件时,由于需要等待组件加载完成后才能显示,因此可能会出现页面空白或显示错误信息的情况。而Suspense组件的作用就是在异步组件加载完成前显示一个占位符,提高用户体验。2、用法首先子组件AsyncShow:使用了promise包裹代码<template><div><h1>{{re......
  • vue监听对象属性值发生变化
    监听对象属性object里面属性值的变化。exportdefault{data(){return{object:{username:'',password:''}}}} 方法一:直接根据watch来监听。exportdefault{data(){......
  • 容器
    vector容器的增长是当容量不够时,就找到一块二倍大的空间,将原来的内容复制到新空间。每一次复制伴有大量的拷贝构造和析构函数的调用,开销大。vector里面有beginendend_of_storge三个迭代器(指针)。list本质是一个双向链表,list类模版里面含有迭代器,list的迭代器里含有一根指针......
  • Springboot K8s Job 一次性任务 如何禁用端口监听
    问题:SpringBoot一次性任务执行时,也会默认监听服务端口,当使用k8sjob运行时,可能多个pod执行存在端口冲突解决办法:命令行禁用SpringBoot一次性任务启动时端口占用java-cp./XXX-Dspring.config.location=/home/XXXX.propertiesorg.springframework.boot.loader.Properties......
  • IOC容器
    namespaceFeng.FramWorkDesign{publicclassIOCContainer{privateDictionary<Type,object>mInstance=newDictionary<Type,object>();publicvoidRegister<T>(Tinstance){varkey=typeof(T);......
  • 如何让公司其他项目组的传统部署迁移到容器部署
    准备好容器环境组织项目方、开发、测试、运维进行容器相关培训评估应用上云的必要性,可行性和风险,综合决定是否上云及哪些部分上云。选择新项目以容器方式部署,新项目稳定后,在对老项目进行推广选择非核心无状态的业务服务优先实践CI/CD流水线相关改造情况一:应用不做任何改......
  • vue3 使用 setup 语法糖时,keep-alive 缓存使用 include / exclude 获取组件名
    <template><router-viewv-slot="{Component,route}"><keep-alive:include="['ComponentName']"><component:is="Component":key="route.name"/></keep-alive>......