products.ts 685 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { defineMock } from "umi";
  2. type Product = {
  3. id: string;
  4. name: string;
  5. age: number;
  6. address: string;
  7. key: string;
  8. };
  9. let products: Product[] = [
  10. {
  11. id: "1",
  12. key: "1",
  13. name: "胡彦斌",
  14. age: 32,
  15. address: "西湖区湖底公园1号",
  16. },
  17. {
  18. id: "2",
  19. key: "2",
  20. name: "胡彦祖",
  21. age: 42,
  22. address: "西湖区湖底公园1号",
  23. }
  24. ];
  25. export default defineMock({
  26. "GET /api/products": (_, res) => {
  27. res.send({
  28. status: "ok",
  29. data: products,
  30. });
  31. },
  32. "DELETE /api/products/:id": (req, res) => {
  33. products = products.filter((item) => item.id !== req.params.id);
  34. res.send({ status: "ok" });
  35. },
  36. });