feature: 购物车完整demo

This commit is contained in:
2022-04-28 11:57:53 +08:00
parent ca37a1831f
commit 6dece8bccc
7 changed files with 155 additions and 16 deletions

35
src/api/shop.ts Normal file
View File

@@ -0,0 +1,35 @@
export interface IProduct {
id: string
name: string
price: number
inventory: number
}
const _products: IProduct[] = [
{
"id": "0",
"name": "IPad Pro",
"price": 5999,
"inventory": 2
},
{
"id": "1",
"name": "IPhone 13 Pro",
"price": 7999,
"inventory": 3
}
]
export const getProducts = async () => {
await wait(1000)
return _products
}
export const buyProducts = async () => {
await wait(1000)
return Math.random() > 0.5
}
async function wait( delay: number ) {
return new Promise(( resolve ) => setTimeout(resolve, delay))
}