axios基本用法

1.用script引入

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

2.axios提供了一下几种请求方式

axios.request(config)

axios.get(url[, config])

axios.delete(url[, config])

axios.head(url[, config])

axios.post(url[, data[, config]])

axios.put(url[, data[, config]])

axios.patch(url[, data[, config]])

3.axios 常用的get 和post 请求实例:

get:axios.get("Sevlet_List")
  .then(function(res) {
	that.items = res.data.result;
	console.log(that.items)
});
post :var param = new URLSearchParams();  //为了解决兼容问题,先声明一个对象
      param.append("gid",gid);   //给对象赋值
      axios.post("Servlet_details",param)  //然后把这个对象传递给后台
       .then(function(res){
	   that.title = res.data.result[0].gname;
})

  

原文地址:https://www.cnblogs.com/donghb/p/7543179.html