鍍金池/ 問答/HTML/ 多次使用axios請求數(shù)據(jù) 第一次的數(shù)據(jù)可以顯示在html上 后面的就不行了

多次使用axios請求數(shù)據(jù) 第一次的數(shù)據(jù)可以顯示在html上 后面的就不行了

<template v-for='obj in topic'>

   <div class='row'>
   <img :src='obj.author.avatar_url' :title="obj.author.loginname"/>
   <span>{{obj.reply_count}}</span>
   <span>/</span>
   <span>{{obj.visit_count}}</span>
   <span>{{obj | tabName}}</span>
   <span>{{obj.title}}</span>
   <span></span>
   <!--就這有l(wèi)astReply不能顯示 其他的數(shù)據(jù)都能顯示 
      這個請求不是第一次請求
   -->
   <img :src='lastReply'/>
   
   <router-link :to="{name:'topic',params:{id:1}}">
     this is root page
   </router-link>
   </div>
 </template>
 
 

getData:async function(){

  var limit=5;
  var data=await axios({
    method:'get',
url:'https://cnodejs.org/api/v1/topics',
params:{
  limit:limit
}
  })
  //這次請求來的數(shù)據(jù)可以顯示到html
  console.log(data.data.data);
  this.topic=data.data.data;
  var id=data.data.data[0].id;
  
  var reply_btw='';
  
 for(var i=0;i<limit;i++){
    id=data.data.data[i].id;
    //這幾次請求來的數(shù)據(jù)可以顯示在控制臺 但在template中就不行了了
    reply_btw=await axios({
                            url:'https://cnodejs.org/api/v1/topic/'+id
                          });

console.log(reply_btw.data.data.replies);
    if(reply_btw.data.data.replies.length<1){
  this.topic[i].lastReply=false;
}
else{
 //所有請求來的數(shù)據(jù)都存到topic里面
  this.topic[i].lastReply=reply_btw.data.data.replies.slice(-1)[0].author.avatar_url;
}

  }
  //最終在控制臺顯示的數(shù)據(jù)是完整的
  console.log(this.topic);
}
回答
編輯回答
焚音

修改數(shù)組用this.$set(data, index, value)
https://cn.vuejs.org/v2/guide...

2017年8月27日 07:29