2016 - 2024

感恩一路有你

axios二次封装及调用 vue中Axios的封装与API接口的管理详解?

浏览量:2499 时间:2021-03-14 18:12:04 作者:admin

vue中Axios的封装与API接口的管理详解?

首先,在您创建的public方法的文件中创建一个新的HttpUtil.js文件文件。以下是总结HttpUtil.js文件内容:VAR Axios=require(“Axios”)//配置项根,例如路径VAR root=“http://localhost:8090/manage“//Axios请求函数httpapi(method,URL,params){返回新承诺((resolve,reject)=>{Axios({method:method,URL:URL,数据:method==“post”;method==“put”?Params:null,Params:Method==“get”| | Method==“delete”?参数:null,baseurl:root,withcredentials:false})。然后((response)=>{解析(response)})。Catch((error)=>{reject(error)})}//返回Vue模板中的调用接口,导出默认值{get:function(URL,parameters){return httpapi(“get”,URL,parameters)},post:function(URL,parameters)},params){return httpapi(“post”,URL,params)},put:function(URL,params){return httpapi(“put”,URLparams)},delete:function(url,params){return httpApi(“delete”,url,params)}

Axios请求拦截。Axios用于网络请求数据。请求拦截是指您发起的请求被系统拦截,响应拦截是指在请求之后,系统有一个响应来拦截它。

axios二次封装及调用 vue封装api怎么封装的啊 axios封装详解

版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。