当前位置:网站首页>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
边栏推荐
- Yum [errno 256] no more mirrors to try solution
- Is blazor ready to serve the enterprise?
- How to add modules to nginx image?
- Dynamsoft barcode reader v7.5!
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- 应用层软件开发教父教你如何重构,资深程序员必备专业技能
- Three steps to understand Kerberos Protocol easily
- Insomnia all night
- CI / CD of gitlab continuous integrated development environment
- Developing STM32 USB with cubemx
猜你喜欢

使用RabbitMQ实现分布式事务

一种超参数优化技术-Hyperopt

11.Service更新

关于DevOps的七大误解,99%的人都曾中过招!

Win7 how to quickly type CMD and get to the required directory

confd

VARCHART XGantt入门教程

8.Swarm创建维护和水平扩展Service

Git submission specification

Application layer software development Godfather teaches you how to refactor, senior programmers must professional skills
随机推荐
PHP backdoor hiding skills
Is blazor ready to serve the enterprise?
Jenkins入门(二)声明式流水线Jenkins Pipeline
心理咨询app开发所具备的优点与功能
[graffiti Internet of things footprints] panoramic introduction of graffiti cloud platform
QT audio and video development 46 video transmission UDP version
K-vim installation and the ycmd server shut down (restart with ': ycmrestartserver')
Mobile pixel adaptation scheme
Application of UHF RFID medical blood management system
Two dimensional code location and alarm system of Expressway
Plug in bilibilibili new version 0.5.5
A kind of super parameter optimization technology hyperopt
20个XR项目路演,近20个资本机构出席!诚邀您参加2020 Qualcomm XR生态合作伙伴大会
C# 枚举权限 |和||,&和&&的区别
LEADTOOLS如何检测,读取和写入条形码
8.Swarm创建维护和水平扩展Service
confd
The first choice for lightweight GPU applications is the NVIDIA vgpu instance launched by Jingdong Zhilian cloud
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Blazor 準備好為企業服務了嗎?