axios的封装

相关标签:
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()
}
文章来源: https://blog.51cto.com/u_15757623/5593385
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报