vant-list 一行两列时,最后一行与其他行间距不一致问题

1.使用vant-list时,会出现以下问题
  watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Y2O6ICM5pyJ6K-G,size_9,color_FFFFFF,t_70,g_se,x_16

 2. 如何解决
添加以下样式即可解决

/deep/.van-list__placeholder{

display:none;

}

 

在 `vant-popup` 中使用 `vant-list`,当数据较少第二次打开弹框会多次触发 `onload` 事件,可从以下几个方面解决: ### 控制加载状态 要保证在加载数据,`loading` 状态设置为 `true`,避免重复触发 `load` 事件。加载完成后,根据实际情况设置 `finished` 状态。 ```vue <template> <van-popup v-model="showPopup"> <van-list v-model:loading="loading" :finished="finished" @load="onLoad" > <!-- 列表内容 --> <div v-for="item in listData" :key="item.id">{{ item.name }}</div> </van-list> </van-popup> </template> <script setup> import { ref } from 'vue'; const showPopup = ref(false); const loading = ref(false); const finished = ref(false); const listData = ref([]); const onLoad = async () => { if (loading.value || finished.value) return; loading.value = true; try { // 模拟异步请求 const newData = await fetchData(); listData.value.push(...newData); // 判断是否还有更多数据 if (newData.length === 0) { finished.value = true; } } finally { loading.value = false; } }; const fetchData = () => { return new Promise((resolve) => { setTimeout(() => { // 模拟获取数据 const newData = [ { id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, ]; resolve(newData); }, 1000); }); }; </script> ``` ### 重置状态 在关闭 `vant-popup` ,重置 `loading` 和 `finished` 状态。 ```vue <template> <van-popup v-model="showPopup" @close="resetListState"> <van-list v-model:loading="loading" :finished="finished" @load="onLoad" > <!-- 列表内容 --> <div v-for="item in listData" :key="item.id">{{ item.name }}</div> </van-list> </van-popup> </template> <script setup> import { ref } from 'vue'; const showPopup = ref(false); const loading = ref(false); const finished = ref(false); const listData = ref([]); const onLoad = async () => { if (loading.value || finished.value) return; loading.value = true; try { // 模拟异步请求 const newData = await fetchData(); listData.value.push(...newData); // 判断是否还有更多数据 if (newData.length === 0) { finished.value = true; } } finally { loading.value = false; } }; const resetListState = () => { loading.value = false; finished.value = false; listData.value = []; }; const fetchData = () => { return new Promise((resolve) => { setTimeout(() => { // 模拟获取数据 const newData = [ { id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, ]; resolve(newData); }, 1000); }); }; </script> ``` ### 检查滚动位置 在打开 `vant-popup` ,确保滚动位置重置,防止因滚动位置问题触发 `load` 事件。 ```vue <template> <van-popup v-model="showPopup" @open="resetScrollPosition"> <van-list v-model:loading="loading" :finished="finished" @load="onLoad" > <!-- 列表内容 --> <div v-for="item in listData" :key="item.id">{{ item.name }}</div> </van-list> </van-popup> </template> <script setup> import { ref } from 'vue'; const showPopup = ref(false); const loading = ref(false); const finished = ref(false); const listData = ref([]); const listRef = ref(null); const onLoad = async () => { if (loading.value || finished.value) return; loading.value = true; try { // 模拟异步请求 const newData = await fetchData(); listData.value.push(...newData); // 判断是否还有更多数据 if (newData.length === 0) { finished.value = true; } } finally { loading.value = false; } }; const resetScrollPosition = () => { if (listRef.value) { listRef.value.scrollTop = 0; } }; const fetchData = () => { return new Promise((resolve) => { setTimeout(() => { // 模拟获取数据 const newData = [ { id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, ]; resolve(newData); }, 1000); }); }; </script> ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

华而有识

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

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

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

打赏作者

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

抵扣说明:

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

余额充值