VUE獲取后台數據


 

這是接口地址

在vue 引入axios

安裝指令:npm install axios --save

在script標簽下引入過后

data() {
    return {
      pageData: []
    };
  },
created() {
   var that=this
    axios
      .get("http://localhost:4277/api/market/People/PagedList")
      .then(res => {
        console.log(res);
        this.pageData = res.data.Data;
      })
      .catch(err => {
        console.log(err);
      });
  }

 

完成

 

 這里遇到一個坑,

vat that=this;  
axios .
get("http://localhost:4277/api/market/People/PagedList") .then(function() { console.log(res); that.pageData = res.data.Data; }) .catch(err => { console.log(err); }); }

 

這是之前的代碼,這樣根本不顯示,原因是function是個內部封閉的函數,this就是function內部本身,無法為pageData賦值,如果要用function,記得先var that=this,然后that.peopleData就可以得到數據了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM