在vue项目中使用axios
2024-09-06 13:27:44
安装
cnpm i axios --save-dev
在项目main.js中全局引用
import axios from "axios"
Vue.prototype.$http=axios;
接下来就可以在项目中通过this.$http使用啦,then函数表示响应成功,catch表示失败
this.$http({
url:"https://api.api68.com/klsf/getLotteryInfo.do?issue=&lotCode=10009",
type:"get"
})
.then((res)=>{
console.log(res);
})
.catch((err)=>{
console.log(err)
})
如果then和catch中的回调函数不是箭头函数,可以通过.bind(this)解决函数内部访问this实例的问题
this.$http({
url:"https://api.api68.com/klsf/getLotteryInfo.do?issue=&lotCode=10009",
type:"get"
})
.then(function(res){
console.log(res);
console.log(this.msg);
}.bind(this))
.catch(function(err){
console.log(err)
}.bind(this))
}
最新文章
- ZOJ 2974 矩阵快速幂
- 在使用EFCodeFirst中出现类型“System.Data.Objects.ObjectContext”在未被引用的程序集中定义的解决方案
- ELK-Python(二)
- Java源码初学_ArrayList
- call的其他应用
- 导出Unity场景为配置文件
- VBS 操作注册表 十六进制
- C语言指针的初始化和赋值
- python网络编程基础(一)
- 数据分析三剑客之Matplotlib
- C#中生成GUID的四种格式
- Android文字转语音引擎(TTS)使用
- 【Checkio Exercise】Three Point Circle
- day0-功能自动化的前提
- Python从菜鸟到高手(5):数字
- ASP.NET MVC 4 (七) 模板帮助函数
- [Android] 图片裁剪总结——调用系统裁剪
- hdu 5385 The path
- nginx搭建负载均衡
- python中hashlib md5
热门文章
- 在使用Hanlp配置自定义词典时遇到的问题
- c++11多线程记录1 -- std::thread
- FORMAT 的用法
- PB 获取或操作数据窗口语句的方法
- Golang ---json解析
- 西门子S7-300 设置IP、子网掩码
- golang中生成读取二维码(skip2/go-qrcode和boombuler/barcode,tuotoo/qrcode)
- aria2 cmd set chmod, and others..
- k8s--complete-demo.yaml
- Gson含抽象类的反序列化