当前位置:网站首页>vue踩坑:axios使用this指针
vue踩坑:axios使用this指针
2020-11-07 16:54:00 【osc_yozufu01】
前言
在vue中,请求后端接口的模块有三种:
- vue-resource
- axios
- fetch
这我们使用axios去请求后端接口。
安装
进入vue项目的目录,执行:
npm install axios --save
使用
axios支持的http请求方法如下
- axios.request(config)
- axios.get(url[, config])
- axios.delete(url[, config])
- axios.head(url[, config])
- axios.options(url[, config])
- axios.post(url[, data[, config]])
- axios.put(url[, data[, config]])
- axios.patch(url[, data[, config]])
本篇不重点介绍axios的使用,这里我们以get为例,在使用axios接收接口返回的时候,需要使用箭头=>符号获取正确的this指针。
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( () {
});
博主:测试生财
座右铭:专注测试与自动化,致力提高研发效能;通过测试精进完成原始积累,通过读书理财奔向财务自由。
csdn:https://blog.csdn.net/ccgshigao
版权声明
本文为[osc_yozufu01]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4323266/blog/4707591
边栏推荐
- ImageMagick - add watermark
- 心理咨询app开发所具备的优点与功能
- 汽车维修app开发的好处与功能
- REM: the solution of PC and mobile
- VARCHART XGantt如何在日历上表示工作日
- How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
- STlink下载出现st-link usb communication error解决方法
- 2020-08-17: how to solve data skew in detail?
- 2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
- 8.Swarm创建维护和水平扩展Service
猜你喜欢

cubemx做stm32 USB开发

图像处理工具包ImagXpress使用教程,如何查看事件

Application of UHF RFID medical blood management system

Practice of Xiaoxiong school development board: real equipment access of smart street lamp sandbox experiment

Web API interface design: swaggerui document / unified response format / unified exception handling / unified authority verification

课堂练习

confd

20个XR项目路演,近20个资本机构出席!诚邀您参加2020 Qualcomm XR生态合作伙伴大会

How to use Gantt chart layers and filters

11.Service更新
随机推荐
September 3, 2020: naked writing algorithm: loop matrix traversal.
7.Swarm搭建集群
Introduction to Jenkins (2) declarative pipeline
JS string - string string object method
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
python3操作gitlab
Application layer software development Godfather teaches you how to refactor, senior programmers must professional skills
A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
And how to solve the conflict between pop-up menu and pop-up menu
[doodling the footprints of Internet of things] Introduction to Internet of things
心理咨询app开发所具备的优点与功能
Test the necessary skill points of siege lion! This article takes you to interpret the testing technology under Devops
LEADTOOLS如何检测,读取和写入条形码
测试攻城狮必备技能点!一文带你解读DevOps下的测试技术
关于DevOps的七大误解,99%的人都曾中过招!
高速公路二维码定位报警系统
Application of UHF RFID medical blood management system
条形码识别性能低,如何优化Dynamsoft Barcode Reader解码性能
ImageMagick - add watermark
yum [Errno 256] No more mirrors to try 解决方法