当前位置:网站首页>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-15: under what circumstances should data tasks be optimized?
- List to map (split the list according to the key, and the value of the same key is a list)
- Design pattern of facade and mediator
- Exclusive interview with Yue Caibo
- Git SSH bad permissions
- Reserved battery interface, built-in charge and discharge circuit and electricity meter, quickly help easily handle hand-held applications
- 2020-08-17: how to solve data skew in detail?
- How to add modules to nginx image?
- python3操作gitlab
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
猜你喜欢

7.Swarm搭建集群

条形码识别性能低,如何优化Dynamsoft Barcode Reader解码性能

使用RabbitMQ实现分布式事务

10000! Ideal car recalls all defective cars: 97 accidents have occurred and losses will be expanded

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

Gantt chart grouping activities tutorial

11. Service update

cubemx做stm32 USB开发

心理咨询app开发所具备的优点与功能

Python3 operating gitlab
随机推荐
课堂练习
“非洲用户的付费意愿并不低”——专访四达时代研发总监张亮
VARCHART XGantt入门教程
如何使用甘特图图层和筛选器
Detailed software engineering -- the necessary graphs in each stage
yum [Errno 256] No more mirrors to try 解决方法
大佬们如何在nginx镜像里面增加模块?
Chinese sub forum of | 2020 PostgreSQL Asia Conference: Pan Juan
K-vim installation and the ycmd server shut down (restart with ': ycmrestartserver')
OpenCV計算機視覺學習(10)——影象變換(傅立葉變換,高通濾波,低通濾波)
RFID fixed assets management system for fire equipment
August 18, 2020: introduce Mr process?
Gantt chart grouping activities tutorial
三步轻松理解Kerberos协议
idea 激活到 2089 失效
Exclusive interview with alicloud database of | 2020 PostgreSQL Asia Conference: Wang Xu
Python 3 operates the Jenkins module API
Experiment one
Bluetooth broadcast chip for Shanghai giant micro
RECH8.0版本学习 days 12 rh134部分