axiso 的使用

Vue官方推荐的ajax请求框架叫做:axios

axios的Get请求语法:

axios.get("/item/category/list?pid=0") // 请求路径和请求参数拼接
    .then(function(resp){
    	// 成功回调函数
     })
    .catch(function(){
    	// 失败回调函数
     })

// 参数较多时,可以通过params来传递参数 axios.get("/item/category/list", { params:{ pid:0 } }) .then(function(resp){})// 成功时的回调 .catch(function(error){})// 失败时的回调

axios的POST请求语法:

axios.post("/user",{
        name:"Jack",
        age:21
    })
    .then(function(resp){
    
    })
    .catch(function(error){
    
    })

注意,POST请求传参,不需要像GET请求那样定义一个对象,在对象的params参数中传参。post()方法的第二个参数对象,就是将来要传递的参数

 

猜你喜欢

转载自www.cnblogs.com/houchen/p/12037588.html