一体化场景下使用中间件封装返回结果,前端调用API函数返回类型没有发生相应改变?
RobertChaw opened this issue · comments
RobertChaw commented
Lxxyx commented
前端可以使用中间件拆包。参考:https://midwayjs.org/docs/hooks/client#middleware-middleware
import { setupHttpClient } from '@midwayjs/rpc';
import type { Middleware } from '@midwayjs/rpc';
const unwrap: Middleware = async (
ctx,
next
) => {
await next();
ctx.res = ctx.res.data
};
setupHttpClient({
middleware: [unwrap],
});
RobertChaw commented
前端可以使用中间件拆包。参考:https://midwayjs.org/docs/hooks/client#middleware-middleware
import { setupHttpClient } from '@midwayjs/rpc'; import type { Middleware } from '@midwayjs/rpc'; const unwrap: Middleware = async ( ctx, next ) => { await next(); ctx.res = ctx.res.data }; setupHttpClient({ middleware: [unwrap], });
好的!谢谢您帮我解决了这个小问题。 🌷🌷