一、什么是axios,axios是用来干什么的
Vue专注于网络请求的一个轻量库,就是用来发请求,没有操作DOM的功能
调用方式
1.axios.get(url).then(res=>{}).catch(err=>{})
2.axios.post(url,data).then(res=>{}).catch(err=>{})
注意在成功或者失败时使用箭头函数声明回调函数,确保函数内部this指向当前vue实例对象
二、axios如何使用
1.导包
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
2.用包
get请求
axios.get("http://www.xxxx.com/weffg_mini?city=sz")
.then(res=>{
console.log(res)
})
.catch(err=>{
console.log(err)
})
post请求
axios.post("http://www.xxxx.com/weffg_mini?city=sz",{
key:"dhfgahgfrghag",
info:"dhfsajh"
})
.then(res=>{
console.log(res)
})
.catch(err=>{
console.log(err)
})
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。