axios总结

axios:

1.作用
1)ajax工具包
2)promise
3)支持请求和响应的拦截
nodejs和网页端都可以使用
2.使用 :
1.安装 npm install axios
2.导入挂载 import axios from ‘axios’
Vue.prototype $http=axios

3.在组件使用:

         this.$http.get(url)
         .then(res=>console.log(res))
         .catch(err=>consloe.log(err))
     get: 1)get(url)
            2)get(url?name=mm&age=19)
            3)get(url,{params:{name:"mm",age:19}})
           
    
     post: 1)post(url,data,config)
             2)post("http://www.mi.com/api/echo",{name:"mm",age:10})
             3)post("http://www.mi.com/api/echo","name="mm"&age=10",{
                      headers:{"Content-Type":"application/x-www-form-urlencoded"}})

     axios(): url:xxx
                method: 方法:post get put delete head
                params:get请求传参  
                            post put 传参 
                            headers请求头信息: “Content-Type” 
                            "Content-Type":"application/json
                            "Content-Type":"application/x-www-form-urlencoded;charset=utf-8"
                            "Content-Type":"multipart/form-data"

你可能感兴趣的:(前端,vue.js,node.js)