我有一个工作购物车状态机来添加我正在使用reactjs 的购物车中的商品。在刷新页面时,上下文未保留。我是状态机新手,想在我的应用程序中保留状态。下面是我的购物车。请帮助。谢谢。
export const cartMachine = Machine(
{
id: "cart",
initial: "idle",
context: {
ItemsInCart: [],
},
states: {
idle: {
on: {
ADD: {
target: "idle",
actions: ["addProductsToCart"],
},
},
},
},
},
/* actions */
{
actions: {
addProductToCart: assign((context, event) => {
const { ItemsInCart } = context;
const { item } = event;
let checkIfProductInCart = ItemsInCart.find(({ id }) => id == item.id);
let canAddToCart = checkIfProductInCart;
if (!canAddToCart) {
ItemsInCart.push({ ...item });
}
}),
}, …Run Code Online (Sandbox Code Playgroud) Nestjs swagger ui 在部署到 vercel 时不加载样式,但在本地运行良好
我使用以下配置添加了 vercel.json 并部署到 vercel。
{
"version": 2,
"builds": [
{
"src": "src/main.ts",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "src/main.ts",
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
主要.ts
const swaggerConfig = new DocumentBuilder()
.setTitle('Tansfun')
.setDescription('API for Tansfun')
.setVersion('1.0')
.addBearerAuth(
{
type: 'http',
scheme: 'bearer',
bearerFormat: 'APIKey',
name: 'APIKey',
description: 'Enter API Key',
in: 'header',
},
'APIKey-auth',
)
.build();
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const …Run Code Online (Sandbox Code Playgroud)