我开始使用
Vite
而不是
CRA
但我无法让代理工作。
我正在使用
json server
对于我的数据库,它位于
http://localhost:3000/customers
对于CRA,我想补充一点
"proxy": "http://localhost:3000",
到
package.json
然后在我的apiSlice中:
const baseQuery = fetchBaseQuery({ baseUrl: "" });
然而,这对Vite不起作用,所以我尝试将其添加到
vite.config
:
server: {
proxy: {
"/api": "http://localhost:3000",
},
},
并改变了我的
baseQuery
到
const baseQuery = fetchBaseQuery({ baseUrl: "/api" });
然而,我在控制台中不断收到此错误:
CustomerList.jsx:4 Uncaught TypeError: useGetCustomersQuery is not a function or its return value is not iterable
useGetCustomersQuery
是我的RTK查询,我认为问题是没有与通信
backend
正如它应该做的那样。