当前位置:网站首页>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
边栏推荐
- confd
- Detailed software engineering -- the necessary graphs in each stage
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王旭
- 使用RabbitMQ实现分布式事务
- 插件Bilibili新版0.5.5
- August 30, 2020: naked write algorithm: the nearest common ancestor of two nodes in a binary tree.
- 汽车维修app开发的好处与功能
- JS string - string string object method
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- August 24, 2020: what are small documents? What's wrong with a lot of small files? How to solve many small files? (big data)
猜你喜欢

WebAPI接口设计:SwaggerUI文档 / 统一响应格式 / 统一异常处理 / 统一权限验证

Two dimensional code location and alarm system of Expressway

Application of UHF RFID medical blood management system

Design of NAND flash interface control

OpenCV計算機視覺學習(10)——影象變換(傅立葉變換,高通濾波,低通濾波)

Gantt chart grouping activities tutorial

How does LeadTools detect, read and write barcodes

New features of vue3

How to deploy Gantt chart quickly and correctly

PHP backdoor hiding skills
随机推荐
应用层软件开发教父教你如何重构,资深程序员必备专业技能
PHP后门隐藏技巧
September 9, 2020: naked writing algorithm: two threads print numbers 1-100 in turn.
2020-08-20: the difference between go and python?
2020-08-17: how to solve data skew in detail?
September 3, 2020: naked writing algorithm: loop matrix traversal.
Exclusive interview with Yue Caibo
A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
【QT】QThread原始碼淺析
Dynamsoft barcode reader v7.5!
【笔记】Error while loading PyV8 binary: exit code 1解决方法
New features of vue3
WebAPI接口设计:SwaggerUI文档 / 统一响应格式 / 统一异常处理 / 统一权限验证
关于DevOps的七大误解,99%的人都曾中过招!
Stm32f030c6t6 compatible to replace mm32spin05pf
傲視Kubernetes(一):Kubernetes簡介
August 24, 2020: what are small documents? What's wrong with a lot of small files? How to solve many small files? (big data)
Introduction to Jenkins (2) declarative pipeline
Win7 AppCrash (solution)
Experiment one