#Axios
- 定义
- 安装
- 挂载
- Get
- Post
- Axios 规则
定义
ajax 工具 与后端交换数据
安装
切换到项目目录 npm i axios -S
挂载
挂载
找到 mian.js 然后
import axios from 'axios'
Vue.prototype.$http=axios;
Get
1.
get(url,{params:{})
url 请求地址
params 请求参数
2.
get(url?a=k1&b=k2)
url 请求地址
a,b 请求参数
例子:
1.通过 axios 给 http://www.520mg.com/mi 发送一个Get 请求
参数是page=5,channel=hot
$http.get
axios.get("http://www.520mg.com/mi?page=5&channel=hot")
.then(res=>{})
.catch(err=>{})
Post
1.
post(url,data,config)
url 请求地址
data 请求内容
config 配置内容
2.
post(url,{a:k1,b:k2},{
headers:{"Content-type":"application/json"}
})