飞道的博客

axios 基础

407人阅读  评论(0)

axios 基础

特征:

  • 从浏览器中创建XMLHttpRequest
  • 从node.js发出http请求
  • 支持Promise API
  • 拦截请求和响应
  • 转换请求和响应数据
  • 取消请求
  • 自动转换JSON数据
  • 客户端支持防止CSRF/XSRF

作用

ajax工具包
promise
支持请求和响应的拦截
nodejs和网页端都可以使用

使用

1,安装
	npm  install axios -S
2.  导入挂载
	import axios from 'axios'
	 vue.prototype.$http = axios
3.  组件中使用
	this.$http.get(url)
	.then(res=>console.log(res))
	.cartch(err=>console.log(err))

get

get(url)
get(url?name=gxx&age=19)
get(url,{params:{name:"gxx",age:18}})

post

post(url,data,config)
post("http://www.mi.com/api/echo",{name:"abc",age:15})
post("http://www.mi.com/api/echo","name:abc&age:15",{
headers:{Content-Type":"application/x-www-form-urlencodeed}

})

axios()

url:xxxx
	地址
method
	方法:|post|get|put|delete|head
params
	get请求传参
data
	post,put  请求传参
headers
	请求头信息
		”Content-Type“
		Content-type:application/json
		Content-type:application/x-www-form-	urlencoded;charset=utf-8
		Content-type:multipart/form-data

转载:https://blog.csdn.net/weixin_46328144/article/details/108472457
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场