<template> <van-pull-refresh v-model="refreshing" @refresh="onRefresh"> <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> <!-- <van-cell v-for="item in courses" :key="item" :title="item.title" /> --> <van-card v-for="item in courses" :key="item" num="2" price="2.00" :desc="item.body" :title="item.id + '-' + item.title" thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg" /> <template slots="loading"> <van-loading class="load-more-loading" /> <span class="load-more-text">加载中...</span> </template> </van-list> </van-pull-refresh> </template> <script> export default { name: "LoadMore", data() { return { list: [], courses: [], loading: false, finished: false, refreshing: false }; }, methods: { onLoad() { setTimeout(() => { if (this.refreshing) { this.courses = []; this.refreshing = false; } for (let i = 0; i < 10; i++) { this.courses.push(this.list[this.courses.length]); } this.loading = false; if (this.courses.length >= 40) { this.finished = true; } }, 3000); }, onRefresh() { // 清空列表数据 this.finished = false; // 重新加载数据 // 将 loading 设置为 true,表示处于加载状态 this.loading = true; this.onLoad(); } }, created() { let url = "http://jsonplaceholder.typicode.com/posts" this.axios.get(url).then((res) => { this.list = res.data }) } }; </script> <style scoped> .load-more-loading { margin-right: 6px; } .load-more-text { font-size: 14px; color: #999; } </style>给每个card内容做一个vue详情页
时间: 2023-12-27 09:05:34 浏览: 85
react-native-smooth-pull-to-refresh:自定义拉动以刷新React Native的组件
可以为每个 `van-card` 组件添加一个点击事件,然后在事件处理函数中跳转到对应的详情页。具体实现可以参考以下代码:
```html
<van-card v-for="item in courses" :key="item" num="2" price="2.00" :desc="item.body"
:title="item.id + '-' + item.title" thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg"
@click="goToDetail(item)"
/>
...
<script>
export default {
...
methods: {
...
goToDetail(item) {
// 获取详情页的路由地址,例如:/detail/1
let detailPath = `/detail/${item.id}`;
// 跳转到详情页
this.$router.push(detailPath);
}
},
...
};
</script>
```
需要注意的是,这里假设你已经配置了 Vue Router,并且详情页的路由地址为 `/detail/:id`,其中 `id` 表示详情页的 ID。你需要根据实际情况来修改路由地址和参数的命名方式。
阅读全文