index.js
725 Bytes
//import axios from "axios";
import store from "@/vuex";
let Axios,success, error;
/**
* @name 统一处理url
* @param {prams} 需要请求的路径
*/
URL=(prams,query=null)=>{
// console.log(process.env);
let url = `${process.env.VUE_APP_URL}${prams.replace(/^\//ig,"")}`;
if(query){
let str = JSON.stringify(query);
str = str.replace(/[{}]/ig,"").replace(/\:/ig,"=").replace(/\,/ig,"&").replace(/["']/ig,"");
url += url.includes("?")? `&${str}`:`?${str}`;
}
return url;
}
export default Axios = (target,name,description)=>{
Object.assign(target.prototype, {
URL,
store,
$axios:axios
})
return target
}