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