在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  HTML/ vue的分頁我一共獲取了total=12條數(shù)據(jù)每頁設置顯示10條,為什么點擊第二

vue的分頁我一共獲取了total=12條數(shù)據(jù)每頁設置顯示10條,為什么點擊第二個頁碼的時候是沒有數(shù)據(jù)的呢?

<template>
<el-main>

<h1>學校通知</h1>
<ul>
  <li v-for='news in tableData'><router-link :to="'/schoolnotice/'+news.newsID">{{news.title}}</router-link><span>{{news.publishTime}}</span></li>
</ul>
        **分頁**
<el-pagination
  layout="prev, pager, next"
  :total="total"
  :page-size="10"
  @current-change="handleCurrentChange"
>
</el-pagination>

</el-main>
</template>

<script>
export default {
data() {

return {
  newsList:[],
  total:{},
  tableData: [], //表格顯示數(shù)據(jù)
  allData: [], //總數(shù)據(jù)
}

},

                             **獲取數(shù)據(jù)**

mounted () {

const that = this;
console.log(that);
this.$http.get(
  that.$interface+'getArticlePages?categoryId=2'
)
  .then(function (response) {
    if(response.data.status === 1){
      response.data.data.list.forEach(function(item){
        that.allData.push({
          title:item.title,
          publishTime:item.publishdate,
          newsID:item.articleid,
        });
        that.total = response.data.data.total;
                    **從allData獲取數(shù)據(jù)到tableData** 
        that.tableData = that.allData.slice(0, 10);
        console.log(that.total);
      });
    }else{
      that.$message({
        message: response.data.msg,
        type: 'warning'
      });
    }
  })
  .catch(function (err) {
    console.log(err);
    that.$message({
      message: '數(shù)據(jù) error',
      type: 'warning'
    })
  });

}, 頁碼點擊事件
methods:{

handleCurrentChange(val) {  //當前頁
  console.log(val);
  this.tableData = this.allData.slice((val - 1) * 10, 10 * val);
}

}
第一頁數(shù)據(jù)

第二頁數(shù)據(jù)

獲取的total值

回答
編輯回答
懶洋洋
  1. 找你們后端,如果是做前端分頁讓他返回所有數(shù)據(jù),也很可能是后端分頁而你們沒對清楚接口

    response.data.data.list.forEach(function(item){
         ...
         console.log(that.total);//打印了10次12 意思是list長度本來就是10
    });
  2. 為什么要在list.forEach里面push,如果你只是想格式化數(shù)組用map。更不要在forEach里重復的執(zhí)行無用的 that.total = ... that.tableData = ...,10次循環(huán)前面9次都是無用的賦值。
2018年5月21日 13:51
編輯回答
久不遇

------------ update

撤回之前的回答, 我看錯了。汗

會不會接口返回的就是 10條數(shù)據(jù)?

2018年7月15日 22:46
編輯回答
離人歸

切換到第二頁的時候,檢查下tableData是不是剩下的那兩條數(shù)據(jù)

2018年7月6日 18:14
編輯回答
傲寒

應該后臺接口有問題,totallist不匹配

2018年6月30日 20:52
編輯回答
法克魷

看一下你的allData是多少條數(shù)據(jù)

2018年4月25日 17:42