认识axios
# 认识axios
# 安装
npm install --save axios
1
axios是一个http库,主要用于向后端发送和请求数据,它主要配合vue.js使用,相当于原生js里面的XMLHttpRequest对象,简写做xhr,我们也叫做ajax库,也相当于jQuery里面的ajax函数
# 了解es6中的Promise
new Promise(function (reslove,reject){
let ok = ' test'
if (ok === 'test') {
reslove('执行成功')
} else {
reject('失败')
}
}).then( param1 =>{
// 执行成功
// param1 === '执行成功'
console.log(param1)
}).catch( error => {
// error === '失败'
console.log(error)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# axios插件的使用
axios({
}).then(res =>{
}).catch(err => {
})
1
2
3
4
5
6
7
2
3
4
5
6
7
# 了解http的请求方法
1.get (params: {})
2.post (data: {})
3.put (data: {})
4.delete
5.patch (data:{})