<template>
<view class="u-page">
<u-list @scrolltolower="scrolltolower">
<view v-for="(item, index) in modelArr" :key="index">
<view style="width:100%;height:100px;">{{item.slug}}</view>
</view>
</u-list>
</view>
</template>
<script>
export default {
data() {
return {
modelArr: [],
page:1,
}
},
onLoad() {
this.clearAndRefreshData()
},
methods: {
clearAndRefreshData() {
this.page = 1
this.requestData()
},
requestData() {
const uri = "wp/v2/posts"
const param = {page:this.page,per_page:10}
getApp().get(uri,param).then(res => {
if (this.page == 1) {
this.modelArr = res
}else{
this.modelArr = this.modelArr.concat(res)
}
if (res.length > 0){
this.page = this.page + 1
}
}).catch(err => {
console.log(err)
})
},
scrolltolower() {
this.requestData()
},
}
}
</script>
<style>
</style>