本文整理匯總了TypeScript中domain-task.fetch函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fetch函數的具體用法?TypeScript fetch怎麽用?TypeScript fetch使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fetch函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getList
export function getList() {
let fetchTask = fetch("/api/list")
.then(r => r.json())
.then(data => (store.list = data))
addTask(fetchTask)
return fetchTask
}
示例2: fetch
requestToArray: (): AppThunkAction<KnownAction> => (dispatch, getState) => {
let fetchTask = fetch(`/api/Stack/ToArray`)
.then(response => response.json() as Promise<Item[]>)
.then(data => dispatch({ type: 'RECEIVE_TOARRAY', items: data }));
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
dispatch({ type: 'REQUEST_TOARRAY' });
}
示例3: fetch
requestStudents: (): AppThunkAction<KnownAction> => (dispatch, getState) => {
let fetchTask = fetch(`api/Students`)
.then(response => response.json() as Promise<Student[]>)
.then(data => {
dispatch({ type: 'RECIVE_STUDENTS', students: data });
});
addTask(fetchTask);
dispatch({ type: 'REQUEST_STUDENTS' });
}
示例4: fetch
requestWeather: (location: string): ActionCreator => (dispatch, getState) => {
if (location !== getState().weather.location) {
let fetchData = fetch(`/api/Weather/${location}`)
.then(response => response.json())
.then((data: Weather) => {
dispatch(new RecieveWeather(data));
})
.catch((error) => {
browserHistory.push('/error');
});
dispatch(new RequestWeather(location));
}
},
示例5: fetch
requestWeatherForecasts: (startDateIndex: number): AppThunkAction<KnownAction> => (dispatch, getState) => {
// Only load data if it's something we don't already have (and are not already loading)
if (startDateIndex !== getState().weatherForecasts.startDateIndex) {
let fetchTask = fetch(`api/SampleData/WeatherForecasts?startDateIndex=${ startDateIndex }`)
.then(response => response.json() as Promise<WeatherForecast[]>)
.then(data => {
dispatch({ type: 'RECEIVE_WEATHER_FORECASTS', startDateIndex: startDateIndex, forecasts: data });
});
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
dispatch({ type: 'REQUEST_WEATHER_FORECASTS', startDateIndex: startDateIndex });
}
}
示例6: fetch
requestCompanies: (userId: number): AppThunkAction<KnownAction> => (dispatch, getState) => {
// Only load data if it's something we don't already have (and are not already loading)
if (userId !== getState().companies.userId) {
let fetchTask = fetch(`http://localhost:5001/api/company?userId=${userId}`)
.then(response => response.json() as Promise<Company[]>)
.then(data => {
dispatch({ type: 'RECEIVE_COMPANIES', userId: userId, companies: data });
});
addTask(fetchTask); // Ensure server-side prerendering waits for this to complete
dispatch({ type: 'REQUEST_COMPANIES', userId: userId });
}
},