在vue中,请求后端接口的模块有三种:vue
这咱们使用axios去请求后端接口。ios
进入vue项目的目录,执行:npm
npm install axios --saveaxios
axios支持的http请求方法以下后端
本篇不重点介绍axios的使用,这里咱们以get为例,在使用axios接收接口返回的时候,须要使用箭头=>符号获取正确的this指针。ide
this.$axios .get("/userInfo") .then( (response) => // handle success (this.userdata = response.data) ) .catch(function (error) { // handle error console.log(error); }) .then(function () { // always executed });
若是不想用箭头函数能够在外部先用变量获取this指针,可是建议仍是使用上面的写法。函数
.$axios .get("/userInfo") .then( function(response){ ) .( (error) { console.log(error); }) .then( () { });
博主:测试生财vue-resource
座右铭:专一测试与自动化,致力提升研发效能;经过测试精进完成原始积累,经过读书理财奔向财务自由。post
csdn:https://blog.csdn.net/ccgshigao测试