小程序+wepy使用vant的van-steps步骤条

vant中的组件是这样的
在这里插入图片描述
项目中的需求样式是
在这里插入图片描述
首先找到steps组件
在这里插入图片描述
在这里插入图片描述
组件中是循环了steps
我修改了绿色框中的代码
在这里插入图片描述
接下来就是数据问题了,回到使用van-steps的页面

<van-steps
   steps="{{steps}}"
   active="{{ active }}"
   direction="vertical"
   active-color="#025BFF"
/>
data = {
    active:0,
    steps:[
      {
        text: '步骤一',
        desc: '描述信息',
        time: '2021-11-30',
      },
      {
        text: '步骤二',
        desc: '描述信息',
        time: '2021-11-30',
      },
    ],
};

小程序使用了wepy框架,所以框架基本还是vue语法
这样就出来了上面项目所需求的样式

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
要实现滚动到底部加载下一页数据,可以使用 `van-list` 中的 `@scroll.native` 事件来监听滚动事件,然后通过计算列表高度和滚动高度来判断是否滚动到了底部。 具体实现步骤如下: 1. 给 `van-list` 组件添加 `ref` 属性,用于获取组件实例。 ```html <van-list ref="list" :finished="isFinished" :loading="isLoading" @load="onLoad"> ... </van-list> ``` 2. 在 `mounted` 钩子函数中,获取 `van-list` 组件实例,并给 `window` 对象添加 `scroll` 事件监听器。 ```typescript import { defineComponent, onMounted, ref } from 'vue'; import { List } from 'vant'; export default defineComponent({ components: { VanList }, setup() { const listRef = ref(null); onMounted(() => { const listInstance = listRef.value.$el; window.addEventListener('scroll', () => { const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; const clientHeight = document.documentElement.clientHeight || document.body.clientHeight; if (scrollTop + clientHeight >= scrollHeight && listInstance.offsetHeight) { // 滚动到底部,触发加载更多 } }); }); return { listRef, }; }, }); ``` 3. 在 `@load` 事件中,将 `isFinished` 和 `isLoading` 属性设置为 `true` 和 `false`,表示数据已经加载完成或正在加载中。 ```typescript export default defineComponent({ components: { VanList }, setup() { const listRef = ref(null); const isFinished = ref(false); const isLoading = ref(false); const onLoad = () => { if (!isFinished.value && !isLoading.value) { isLoading.value = true; // 发送网络请求,获取下一页数据 // 请求成功后,将 isLoading 设置为 false,表示加载完成 } }; onMounted(() => { const listInstance = listRef.value.$el; window.addEventListener('scroll', () => { const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; const clientHeight = document.documentElement.clientHeight || document.body.clientHeight; if (scrollTop + clientHeight >= scrollHeight && listInstance.offsetHeight) { onLoad(); } }); }); return { listRef, isFinished, isLoading, onLoad, }; }, }); ``` 这样,当滚动到底部时,就会触发 `onLoad` 方法,从而加载下一页数据。需要注意的是,在数据全部加载完成后,需要将 `isFinished` 设置为 `true`,以防止重复加载数据。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值