本文整理匯總了TypeScript中domain-task/fetch.fetch函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fetch函數的具體用法?TypeScript fetch怎麽用?TypeScript fetch使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fetch函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: fetch
requestGenresList: (): ActionCreator => (dispatch, getState) => {
if (!getState().genreList.isLoaded) {
fetch('/api/genres')
.then(results => results.json())
.then(genres => dispatch(new ReceiveGenresList(genres)));
}
}
示例2: fetch
userList: (): ActionCreator => (dispatch, getState) => {
fetch(`/users`,{ method: 'GET'})
.then(response => response.json())
.then((data: any) => {
dispatch(new UserList(data.data));
});
dispatch(new UserLoad());
},
示例3: fetch
requestFeaturedAlbums: (): ActionCreator => (dispatch, getState) => {
if (!getState().featuredAlbums.isLoaded) {
fetch('/api/albums/mostPopular')
.then(results => results.json())
.then(albums => dispatch(new ReceiveFeaturedAlbums(albums)));
return dispatch(new RequestFeaturedAlbums());
}
}
示例4: getState
vote: (pollId: number, choiceId: number): ActionCreator => (dispatch, getState) => {
let bearer = getState().auth.token;
fetch(`/api/polls/${pollId}/choices/${choiceId}`, {
method: 'post',
headers: {
'Authorization': `Bearer ${bearer}`,
}
});
}
示例5: dispatch
userItem: (UUID,callback): ActionCreator => (dispatch, getState) => {
dispatch(new UserItem(UserModel.Model));
fetch(`/users/`+UUID,{ method: 'GET'})
.then(response => response.json())
.then((data: any) => {
dispatch(new UserItem(data.data));
callback();
});
dispatch(new UserLoad());
},
示例6: fetch
requestWeatherForecasts: (startDateIndex: number): ActionCreator => (dispatch, getState) => {
// Only load data if it's something we don't already have (and are not already loading)
if (startDateIndex !== getState().weatherForecasts.startDateIndex) {
fetch(`/api/SampleData/WeatherForecasts?startDateIndex=${ startDateIndex }`)
.then(response => response.json())
.then((data: WeatherForecast[]) => {
dispatch(new ReceiveWeatherForecasts(startDateIndex, data));
});
dispatch(new RequestWeatherForecasts(startDateIndex));
}
}
示例7: fetch
requestAlbumDetails: (albumId: number): ActionCreator => (dispatch, getState) => {
// Only load if it's not already loaded (or currently being loaded)
if (albumId !== getState().albumDetails.requestedAlbumId) {
fetch(`/api/albums/${ albumId }`)
.then(results => results.json())
.then(album => {
// Only replace state if it's still the most recent request
if (albumId === getState().albumDetails.requestedAlbumId) {
dispatch(new ReceiveAlbumDetails(album));
}
});
dispatch(new RequestAlbumDetails(albumId));
}
}