<script src="../js/axios.js"></script>
<script src="../js/vue.js"></script>
<script>
//1. 发送get 请求
//通过传统的url 以 ? 的形式传递参数
axios.get('http://127.0.0.1:30021/staffSelect/list?page=1&&limit=10').then(response=>{
//注意data属性是固定的用法,用于获取后台的实际数据
console.log(response.data);//Object { code: 0, msg: "", data: (10) […], count: 27476 }
console.log(response);//Object { data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, request: XMLHttpRequest }
});
//2.发送get请求
//restful 形式传递参数 http://127.0.0.1:30021//menu/get/{}
axios.get('http://127.0.0.1:30021//menu/get/1').then(function(reponse){
//Object { result: true, data: {…}, msg: "查询成功" }
console.log(reponse.data);
});
//3. 通过params形式传递参数
axios.get('http://127.0.0.1:30021/staffSelect/list',{
params:{
page:1,
limit:10
}
}).then(response=>{
//注意data属性是固定的用法,用于获取后台的实际数据
console.log(response.data);//Object { code: 0, msg: "", data: (10) […], count: 27476 }
console.log(response);//Object { data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, request: XMLHttpRequest }
});
//4. axios delete 请求传参 传参的形式和 get 请求一样
axios.delete('http://localhost:3000/axios', {
params: {
id: 111
}
}).then(rep=>{
console.log(rep.data);
});
</script>