当前位置:网站首页>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 - 添加水印
- 谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
- The advantages and functions of psychological counseling app
- How does LeadTools detect, read and write barcodes
- 快進來!花幾分鐘看一下 ReentrantReadWriteLock 的原理!
- Implementation of nginx version of microservice architecture
- 抽絲剝繭——門面和調停者設計模式
- Plug in bilibilibili new version 0.5.5
- About Devops seven misunderstandings, 99% of people have been hit!
- Three steps to understand Kerberos Protocol easily
猜你喜欢

Do you really know how to use search engines?

嘉宾专访|2020 PostgreSQL亚洲大会中文分论坛:岳彩波

Win7 AppCrash (solution)

CI / CD of gitlab continuous integrated development environment

垃圾分类知识竞赛

Come on in! Take a few minutes to see how reentrantreadwritelock works!

Detailed software engineering -- the necessary graphs in each stage

PHP backdoor hiding skills

Getting started with varhart xgantt

A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
随机推荐
Is blazor ready to serve the enterprise?
如何利用PopupWindow实现弹出菜单并解决焦点获取以及与软键盘冲突问题
Nonvolatile MRAM memory used in all levels of cache
频收罚单的浦发银行:增收不增利,曾遭骗贷数亿元,内控缺位?
谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
The use of Xunwei imx6 development board device tree kernel menuconfig
南京标识标牌设计制作,导视VI系统设计
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
Stm32f030c6t6 compatible to replace mm32spin05pf
Application layer software development Godfather teaches you how to refactor, senior programmers must professional skills
In 2020, how can wechat seal numbers be quickly lifted?
2020-08-19: what mechanism does TCP ensure reliability?
2020-11-06:go中,谈一下调度器。
CI / CD of gitlab continuous integrated development environment
2020-11-06: go, let's talk about the scheduler.
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王旭
Solution to st link USB communication error in stlink Download
傲視Kubernetes(一):Kubernetes簡介
高速公路二维码定位报警系统
测试攻城狮必备技能点!一文带你解读DevOps下的测试技术