1
export const authCheckApi = createApi({
  reducerPath: 'authCheckApi',
  baseQuery: fetchBaseQuery({
    baseUrl: 'http://localhost:4001',
  }),

  endpoints: (builder) => ({
    checkAuth: builder.query({
      query: (username, password) => ({
        url: `/user/login/`,
        method: 'POST',
        body: { email: username, password: password },
        headers: {
          'Content-type': 'application/json; charset=UTF-8',
        },
      }),
    }),

    //endPoints end braces below
  }),
  //main end below
});
4

1 回答 1

2

它有点错过了这个问题,但似乎你几乎就在那里 - 但query只从用户输入中获取一个参数,所以你必须将用户名和密码都放入第一个参数中。

        query:({ username, password })=>({
            
            url:`/user/login/`,
            method:'POST',
            body:{email:username,password:password},
            headers:{
                'Content-type': 'application/json; charset=UTF-8',                   
            },

        })
于 2021-09-21T21:38:48.600 回答