溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

vue請求服務器數(shù)據(jù)后綁定不上的解決方法

發(fā)布時間:2020-08-31 16:36:51 來源:腳本之家 閱讀:184 作者:零食粉碎機 欄目:web開發(fā)

后臺返回的數(shù)據(jù),json類型

{"success":1,"tagList":[{"Id":1,"name":"林俊杰"},{"Id":2,"name":"MV"},{"Id":3,"name":"三次元"},{"Id":4,"name":"燃"},{"Id":5,"name":"宅"}]}

Vue綁定UI的代碼

<div class="tag-wrapper">
  <a class="tag-item" v-for="item in tagList">{{item.name}}</a>
</div>

下面是Vue請求數(shù)據(jù)的代碼

var hotTag=new Vue({
   el:".tag-wrapper",
   data:{
    tagList:[],
    selected_num:0
   },
   mounted:function(){
    this.init();
   },
   methods:{
    init:function(){
     axios.get("handle/getHotTag").then( function(result) {
      this.tagList = result.data.tagList;
    })
     // axios.get("handle/getHotTag").then( (result) => {
     //  this.tagList = result.data.tagList;
     // })
 
    }
   }
 
  });

出來的結(jié)果是空的,a.tag-item沒有出現(xiàn),但是在init函數(shù)中打印this.tagList則是存在數(shù)據(jù)的。

將函數(shù)換成雙箭頭形式發(fā)現(xiàn)成功的綁定上了,原因還不知道

 axios.get("handle/getHotTag").then( (result) => {
      this.tagList = result.data.tagList;
     })

以上這篇vue請求服務器數(shù)據(jù)后綁定不上的解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI