首页 > 解决方案 > how can I get all the date from a multiple pages from a json api?

问题描述

There are 61 pages in this json file but with this call I only get the first page of it? How can I get all of them, please? Is there a loop or another way to use axios?

  <template>
  <div id="app">
    
      <thead>
     
      </thead>
      <tbody>
      {{items}}
      </tbody>

  
  </div>

</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      items:[]
    }
  },


  created() {
    axios.get(`https://zbeta2.mykuwaitnet.net/backend/en/api/v2/media-center/press-release/?page=2&page_size=12&type=5`)
    .then(response => {
     
      this.items = response
    })
    
  }
}

</script>

标签: jsonapivue.js

解决方案


尝试不使用?page=2&page_size=12&type=5

axios.get(`https://zbeta2.mykuwaitnet.net/backend/en/api/v2/media-center/press-release/`)

或者您可以设置每页要接收的文章数量(在您的情况下为 61 页,每页 12 篇文章):

axios.get(`https://zbeta2.mykuwaitnet.net/backend/en/api/v2/media-center/press-release/?page=1&page_size=732&type=5`)

推荐阅读