axios
Posted web前端
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了axios相关的知识,希望对你有一定的参考价值。
import axios from "axios";
axios.defaults.baseURL = "xxxxx";
// axios.changeOrigin=true;
export let gethotsongs =(e) => {
return request("xxxx",e,"GET")
};
function timeFormat() {
var d = new Date(),
year = d.getFullYear(),
month = d.getMonth() + 1,
day = d.getDate(),
hours = d.getHours(),
minutes = d.getMinutes(),
seconds = d.getSeconds();
// 补零处理
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
if (hours < 10) hours = "0" + hours;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return (
year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds
);
}
签约算法的时间函数
import axios from "axios";
// const API_PROXY = "https://bird.ioliu.cn/v1/?url=";
// var ApiUrl = "http://b.baidu.com";
axios.defaults.baseURL = "http://localhost:3000";
// axios.defaults.baseURL = "https://musicapi.leanapp.cn";
export function request(config) {
// 1.创建axios实例
var instance = axios.create({
baseURL: "http://localhost:3000",
// baseURL: API_PROXY+"http://localhost:3000",
timeout: 5000
});
instance.interceptors.request.use(
function(config) {
axios.defaults.withCredentials = true;
return config;
},
function(error) {
return Promise.reject(error);
}
);
instance.interceptors.response.use(
res => {
return res;
},
err => {
return Promise.reject(err);
}
);
return instance(config);
}
// export default axios;
export let gethotsongs = () => {
return axios.get("xxx");
};
以上是关于axios的主要内容,如果未能解决你的问题,请参考以下文章