本文整理汇总了TypeScript中axios类的典型用法代码示例。如果您正苦于以下问题:TypeScript axios类的具体用法?TypeScript axios怎么用?TypeScript axios使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了axios类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: loadTodos
static loadTodos() {
let options = {
url: apiBaseUrl,
method: 'GET'
};
return axios(options).then(response => response.data as Todo[]);
}
开发者ID:josephjeganathan,项目名称:react-redux-typescript,代码行数:8,代码来源:todoApi.ts
示例2: toggleTodo
static toggleTodo(id: number) {
let options = {
url: `${apiBaseUrl}/toggle`,
data: {
id: id
},
method: 'POST'
};
return axios(options).then(response => response.data as Todo);
}
开发者ID:josephjeganathan,项目名称:react-redux-typescript,代码行数:11,代码来源:todoApi.ts
示例3: addTodo
static addTodo(text: string) {
let options = {
url: apiBaseUrl,
data: {
text: text
},
method: 'POST'
};
return axios(options).then(response => response.data as Todo);
}
开发者ID:josephjeganathan,项目名称:react-redux-typescript,代码行数:11,代码来源:todoApi.ts
示例4: function
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);
};
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:20,代码来源:request.ts
示例5: 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));
});
};
开发者ID:code-mancers,项目名称:interceptor,代码行数:40,代码来源:aliases.ts
示例6: return
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");
}
};
开发者ID:roryaronson,项目名称:farmbot-web-frontend,代码行数:22,代码来源:actions.ts
示例7: 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;
};
开发者ID:nozzlegear,项目名称:nominatim-browser,代码行数:16,代码来源:nominatim-browser.ts
注:本文中的axios类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论