feature: 购物车完整demo
This commit is contained in:
35
src/api/shop.ts
Normal file
35
src/api/shop.ts
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user