学堂 学堂 学堂公众号手机端

axios的封装

lewis 2年前 (2024-03-11) 阅读数 10 #技术


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()
}



版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门