我在本地测试了我的应用程序,没有任何问题,因此我在import { ActionType, getType } from "typesafe-actions";
import * as Actions from './actions';
import { Profile } from "../../app/models/Profile";
// reducer
export type ProfileAction = ActionType<typeof Actions>;
export type State = {
profiles: Profile[];
errorMessage: string;
loading: boolean;
};
const INITIAL_STATE = {
profiles: [],
errorMessage: null,
loading: false,
};
export default (state: State = INITIAL_STATE, action: ProfileAction): State => {
switch (action.type) {
case getType(Actions.getProfilesRequest): return {
...state,
loading: true,
};
case getType(Actions.getProfilesSuccess): return {
...state,
profiles: action.payload.profiles,
// ERROR: Property 'payload' does not exist on type 'EmptyAction<string> | PayloadAction<string, { profiles: Profile[]; }> | PayloadAction<string, { error: ApiErrorResponse; }>'.
// Property 'payload' does not exist on type 'EmptyAction<string>'. [2339]
loading: false,
};
case getType(Actions.getProfilesRequest): return {
...state,
errorMessage: action.payload.error.message,
// ERROR: Property 'payload' does not exist on type 'EmptyAction<string> | PayloadAction<string, { profiles: Profile[]; }> | PayloadAction<string, { error: ApiErrorResponse; }>'.
// Property 'payload' does not exist on type 'EmptyAction<string>'. [2339]
loading: false,
};
default: return state;
}
};
上部署了graphql-yoga
后端,每次执行请求时都会收到此错误:
从原点“ https://app-api-jg80zv10z.now.sh/”到“ http://localhost:8080”的获取操作已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否“ Access-Control-Allow-来源的标头出现在请求的资源上。如果不透明的响应满足您的需求,请将请求的模式设置为“ no-cors”以在禁用CORS的情况下获取资源。
在我的apollo-client提取策略上,将其设置为“ no-cors”。
尝试在graphql-yoga上使用此选项
Zeit
但仍然无法正常工作。 有人可以帮助我吗?预先感谢。