当前位置:网站首页>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
边栏推荐
- 失眠一个整晚上
- 2020-08-20: the difference between go and python?
- 11.Service更新
- Jenkins入门(二)声明式流水线Jenkins Pipeline
- Insomnia all night
- Gantt chart grouping activities tutorial
- [original] the impact of arm platform memory and cache on the real-time performance of xenomai
- In 2020, how can wechat seal numbers be quickly lifted?
- September 3, 2020: naked writing algorithm: loop matrix traversal.
- PHP backdoor hiding skills
猜你喜欢
Developing STM32 USB with cubemx
VARCHART XGantt入门教程
图像处理工具包ImagXpress使用教程,如何查看事件
STlink下载出现st-link usb communication error解决方法
JVM class loading mechanism
k-vim安装及The ycmd server SHUT DOWN (restart with ':YcmRestartServer')这种错误的解决方法
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
傲視Kubernetes(一):Kubernetes簡介
小程序商城系统插件代码该如何写?怎么用代码检查添加插件是否成功?
南京标识标牌设计制作,导视VI系统设计
随机推荐
10000! Ideal car recalls all defective cars: 97 accidents have occurred and losses will be expanded
Dynamsoft barcode reader v7.5!
【QT】QThread原始碼淺析
September 9, 2020: naked writing algorithm: two threads print numbers 1-100 in turn.
Characteristics of magnetic memory chip STT-MRAM
Exclusive interview with Yue Caibo
python3操作gitlab
Composition of MRAM cache
Introduction to Jenkins (2) declarative pipeline
嘉宾专访|2020 PostgreSQL亚洲大会中文分论坛:岳彩波
.NETCore3.1+ Vue.js Low code workflow engine
Mate 40系列发布 搭载华为运动健康服务带来健康数字生活
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
课堂练习
【原創】ARM平臺記憶體和cache對xenomai實時性的影響
Logo design company, Nanjing
C# 枚举权限 |和||,&和&&的区别
LEADTOOLS如何检测,读取和写入条形码
August 14, 2020: what are the execution engines for data tasks?
Google browser realizes video playback acceleration function