【发布时间】:2021-08-26 21:40:47
【问题描述】:
你好,我想在无限加载我的数据后显示数据通过 asyncData 发送到页面和像这样的 id 页面
Page
<script>
export default {
async asyncData({ $axios, store }) {
const customerId = store.getters['user/auth/customerId']
if (!customerId) {
return
}
const products = await customerApi.getProducts(
{ $axios },
customerId,
this.page
)
return {
products,
}
},
data() {
return {
page: 1,
}
},
}
</script>
我有第一页的数据。 products 是我模板中发送的道具数据。在我的模板中,我添加了无限加载
template
<template>
<generic-button v-if="!viewMore" inline @click="viewMore = true">
see more
</generic-button>
<client-only v-else>
<infinite-loading
:distance="800"
force-use-infinite-wrapper
@infinite="infiniteHandler"
></infinite-loading>
</client-only>
</template>
<script>
export default {
components: {
InfiniteLoading: () =>
process.client
? import('vue-infinite-loading')
: Promise.resolve({ render: (h) => h('div') }),
},
props: {
products: {
type: Array,
required: true,
},
},
data() {
return {
page: 1,
}
},
methods: {
infiniteHandler($state) {
// the method that will look for the data when the pagination changes
},
},
}
</script>
我希望在开始分页时通过将页面参数更改为 +1 来重新启动 asyncData 请求并显示数据
谢谢
【问题讨论】:
-
那么,您正在寻找在滚动时加载下一页的内容?像这样的东西? github.com/kissu/pet-friends
-
我已经把你的问题格式化了,请下次努力。
标签: javascript vue.js nuxt.js