Get Post请求开发但如何在VUE中实施的最常见和最常见的请求方法。这是配置过程的记录,const repuests = axios。
标题:{//这里的参数可以根据您的需要设置“ content-type”:“ application/x-www-forllencod”,而无需。,“ lng-lat”:“”,“ system-version”:“”,“移动模型”:“”,“设备”:“”,“”,}})
//配置请求interceptor requests.interceptors.request.use((config)=> {//配置配置对象返回config}))
//响应interceptor requests.interceptors.response.use.use(((reves)=> {//请求成功返回resp.data},(error)=> {console.log('请求失败................................................................................................................................
导出默认请求
//从'https://www.shouxicto.com/article/request导入基本类导入请求'
const http = {get(url,params){const config = {medhod:“ get”,url:url} if(params){config.params = params} return request(config)},post(url,params){const config = {方法:“ post”,url:url} if(params){config.data = params;console.log('the the the transmittes ===========' + params.phone)} returnRequest(config)}}}}
导出默认HTTP
//导入请求方法类导入http从'https://www.shouxicto.com/article/http'
//定义获取验证代码的方法。
//再次写一个get请求的示例。我根据需要在这里写的参数。在这里,我在这里直接写了它,以声明一个参数传递到导出函数getBillist(){return http.get(“/api // api // api/bill/billlist”,{“ homepore_id”:“ 10131”,“ pay_status”:“ 1”,“ community_id”:“ 10”,“年”:“ 2022”}}}}}}}}}}
//在模板中声明两个点击事件
//从'@/api'导入请求api导入{getBillist,getmsgcode}
//实现请求方法const loadata =()=> {getBillist()。然后((RES)=> {console.log(“请求成功返回值” + res.code + res.msg);})。)(错误)=> {console.log('请求失败返回值')})}}}
原始:https://juejin.cn/post/709863675033542663