返回

axios的封装

发布时间:2022-09-16 16:31:46 280
import http from './http/index'
Vue.use(http);
//import {http} from './http/index'
//Vue.prototype.$http=http;

如下是index文件

import axios from 'axios'
export const http=async function(){
function But(){
return new Promise((resolve,reject)=>{
// resolve({a:1,b:2})
// reject({err:500})
const data={
params:{
a:"132"
}
}
const header={
header:{
"Contene-Type":"application/json"
}
}
//application/x-www-form-urlencoded
axios.get("http://localhost:8000/tp5/publica/index/Http/index",data,header).then(
(res)=>{resolve(res)}
).catch(()=>{
(res)=>{reject(res)}
})
})
}

return await But();
}
const install=function(Vue,options){
Vue.prototype.$http=async function(){
function But(){
return new Promise((resolve,reject)=>{
// resolve({a:1,b:2})
// reject({err:500})
const data={
params:{
a:"132"
}
}
const header={
header:{
"Contene-Type":"application/json"
}
}
//application/x-www-form-urlencoded
axios.get("http://localhost:8000/tp5/publica/index/Http/index",data,header).then(
(res)=>{resolve(res)}
).catch(()=>{
(res)=>{reject(res)}
})
})
}

return await But();
}
}
export default{
install//用于结合vue.use()
}

 

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线