本文整理汇总了TypeScript中axios.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript axios.default方法的具体用法?TypeScript axios.default怎么用?TypeScript axios.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类axios
的用法示例。
在下文中一共展示了axios.default方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: axios
export default
function({ method = 'get', headers = {}, url='', params = {}, data = {} } = {}){
if(!_.isFunction(axios[method]))
return Promise.reject({
code : 500,
message : `Error: HTTP method "${method}" is undefined.`
});
method = method.toLowerCase();
return axios({
url,
method,
params, // the URL parameters to be sent with the request
data, // the data to be sent as the request body, only applicable for request methods 'PUT', 'POST', and 'PATCH'
headers : commonHTTPHeaders
})
.then(HTTPSuccessFn)
.catch(HTTPFailedFn);
};
示例2: loadTodos
static loadTodos() {
let options = {
url: apiBaseUrl,
method: 'GET'
};
return axios(options).then(response => response.data as Todo[]);
}
示例3: toggleTodo
static toggleTodo(id: number) {
let options = {
url: `${apiBaseUrl}/toggle`,
data: {
id: id
},
method: 'POST'
};
return axios(options).then(response => response.data as Todo);
}
示例4: addTodo
static addTodo(text: string) {
let options = {
url: apiBaseUrl,
data: {
text: text
},
method: 'POST'
};
return axios(options).then(response => response.data as Todo);
}
示例5: Axios
/**
Creates a webrequest to the given path.
*/
function createRequest<T>(path: string, data: Object = {}) {
//Result should be in JSON
data["format"] = "json";
const request = Axios({
url: `https://nominatim.openstreetmap.org/${path}`,
method: "GET",
params: data,
responseType: "json",
});
return request;
};
示例6: return
return (dispatch: any) => {
const { method, url, requestId, requestHeaders, tabId } = payload.payload.requestDetails;
const requestHeadersObject = requestHeaders
? requestHeaders.reduce(
(accumulatedObj = {}, reqHeaderNameValuePair: reqHeaderNameValuePair) => {
accumulatedObj[reqHeaderNameValuePair.name] = reqHeaderNameValuePair.value;
return accumulatedObj;
},
{}
)
: {};
dispatch(fetchingResponse(tabId,requestId,true));
axios({
method,
url,
requestHeadersObject
})
.then(({ data, headers }: axios.AxiosResponse) => {
const stringifiedData = headers["content-type"].includes("json")
? JSON.stringify(data, null, 2)
: data;
dispatch(fetchSuccess("", requestId, tabId));
dispatch(handleRespTextChange(stringifiedData, requestId, tabId));
dispatch(fetchSuccess(stringifiedData, requestId, tabId));
})
.catch(() => {
dispatch(
fetchFailure(
"Couldn't connect to server. Check your connection and try again.",
requestId,
tabId
)
);
})
.finally(()=>{
dispatch(fetchingResponse(tabId,requestId,false));
});
};
示例7: Error
return (dispatch, getState) => {
let state = getState().auth;
if (state) {
// https://github.com/mzabriskie/axios/issues/312
axios<{}>({
method: "delete",
url: API.current.usersPath,
data: payload,
params: { force: true }
})
.then(resp => {
alert("We're sorry to see you go. :(");
Session.clear();
window.location.href = "/";
})
.catch((e: AxiosErrorResponse) => {
error(prettyPrintApiErrors(e));
});
} else {
throw new Error("Impossible");
}
};