element-plus [Component] [scrollbar] scrollbar and v-infinite-scroll="load";if use them together , v-infinite-scroll will not get triggered

vfwfrxfs  于 5个月前  发布在  其他
关注(0)|答案(8)|浏览(57)

Bug Type: Component

Environment

  • Vue Version: 3.2.47
  • Element Plus Version: 2.3.4
  • Browser / OS: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
  • Build Tool: Vite

Reproduction

  • el-scrollbar

Element Plus Playground

Steps to reproduce

<template>
  <ArticleCard :title="title">
     <el-scrollbar> <!-- bug:影响load方法触发 -->
    <ul
      v-infinite-scroll="load"
      :infinite-scroll-immediate="false"
      class="infinite-list"
      :infinite-scroll-disabled="disabled"
    >
      <li>
      </li>
      <li v-if="loading" class="infinite-list-otherItem">Loading..</li>
      <li v-if="noMore" class="infinite-list-otherItem">No more</li>
    </ul>
    <</el-scrollbar>
  </ArticleCard>
</template>

<script lang="ts" setup>
import moment from "moment";
import { fetchArticles } from "@/service";

type ArticleInfo = {
  articleInfoList: Array<any>;
  total: number;
};

defineProps<{ title: string }>();

const router = useRouter();

const pageSize = ref(4);
const currentPage = ref(1);
const loading = ref(false);
const articleInfo = reactive<ArticleInfo>({
  articleInfoList: [],
  total: 0,
});

const load = () => {
  console.log(111);
  loading.value = true;
  init();
};

const formatDate = (time: string) => {
  return moment(time).format("YYYY-MM-DD HH:mm:ss");
};

const init = async () => {
  const { data } = await fetchArticles({
    pageSize: pageSize.value,
    currentPage: currentPage.value,
  });

  loading.value = false;
  if (data && data.list.length > 0) {
    // 避免返回空数据
    // console.log("data", data); // 获取首页展示的文章信息
    articleInfo.total = data?.total ?? 0;
    articleInfo.articleInfoList = articleInfo.articleInfoList.concat(
      data?.list ?? []
    );
    currentPage.value += 1;
  }
};

const handleClick = (id: string) => {
  router.push({ path: "/detail", query: { id: id } });
};

const noMore = computed(() => {
  return currentPage.value * pageSize.value > articleInfo.total;
});
const disabled = computed(() => {
  return loading.value || noMore.value;
});

init();

</script>

What is Expected?

load get triggered

What is actually happening?

trigger once because of the init()

Additional comments

(empty)

nfeuvbwi

nfeuvbwi1#

You can try the ElementPlus new Infinite Scroll

ev7lccsx

ev7lccsx2#

You can try the ElementPlus new Infinite Scroll

I am using the latest element-plus😵‍💫

It worked in the past, yesterday i found the bug

mzsu5hc0

mzsu5hc03#

https://element-plus.gitee.io/zh-CN/component/infinite-scroll.html#%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95

xsuvu9jc

xsuvu9jc4#

https://element-plus.gitee.io/zh-CN/component/infinite-scroll.html#%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95

你是真不看我贴的代码啊,哥们

e0bqpujr

e0bqpujr5#

https://element-plus.gitee.io/zh-CN/component/infinite-scroll.html#%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95

你是真不看我贴的代码啊,哥们

按照文档上的内容直接吧v-infinite-scroll加在el-scrollbar上还是不能正常触发load,控制台查看发现v-infinite-scroll被设置在了外层容器上,没有在el-scrollbar__view上。

13z8s7eq

13z8s7eq6#

https://element-plus.gitee.io/zh-CN/component/infinite-scroll.html#%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95

你是真不看我贴的代码啊,哥们

按照文档上的内容直接吧v-infinite-scroll加在el-scrollbar上还是不能正常触发load,控制台查看发现v-infinite-scroll被设置在了外层容器上,没有在el-scrollbar__view上。

文档里是没有这两者配合使用的;
所以我是不是可以理解成scrollbar和无限列表的监听下滑到底部的事件会冲突,也就默认说这两个不能在一起使用;

ccrfmcuu

ccrfmcuu7#

https://element-plus.gitee.io/zh-CN/component/infinite-scroll.html#%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95

你是真不看我贴的代码啊,哥们

按照文档上的内容直接吧v-infinite-scroll加在el-scrollbar上还是不能正常触发load,控制台查看发现v-infinite-scroll被设置在了外层容器上,没有在el-scrollbar__view上。

文档里是没有这两者配合使用的; 所以我是不是可以理解成scrollbar和无限列表的监听下滑到底部的事件会冲突,也就默认说这两个不能在一起使用;

scrollbar应该是不行的,我试了也是这样,scrollbar自身的滚动条到底不触发

vmpqdwk3

vmpqdwk38#

scrollbar用scroll事件,当抵达底部时触发加载添加数据,自己写一个方法判断是否触底,参考这个 https://blog.csdn.net/weixin_47586598/article/details/125025313

相关问题