React商城项目

刚学完react很多都不是很熟练,随便写个商城项目

    • 技术栈
    • 页面
    • 路由

技术栈

需要node和源码的 评论或者私信噢

框架是antd,用到了react-router-dom,redux

react17.0.2版本 react-router-dom v6版本

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://127.0.0.1:1024/api",
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "antd": "^4.17.4",
    "http-proxy-middleware": "^2.0.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.0.2",
    "react-scripts": "4.0.3",
    "redux": "^4.1.2",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "axios": "^0.24.0"
  }
}

页面

首页的效果图如下:
React商城项目_第1张图片
这里用到了数据的懒加载

商品的分类效果图如下
React商城项目_第2张图片
页面有点丑 也没有UI 没得办法

商品的详情页效果图如下
React商城项目_第3张图片
详情页主要功能包括了放大镜 加入购物车
React商城项目_第4张图片
当然 放大镜是手写的 小盒子的没有写 只写了放大后盒子的效果

注册登录就不放图了 没什么好看的

购物车效果图如下
React商城项目_第5张图片
搜索功能效果图如下
React商城项目_第6张图片

路由

页面不多总共8个,拿来练手正正好好,有个不解的地方就是想在路由中拿到props.localtion.key,有大佬知道可以评论或者私信告诉我下。

import React from "react";
import { BrowserRouter, Route, Routes, useParams } from "react-router-dom";
import Home from "../test/home";
import Zhuce from "../test/zhuce";
import Login from '../test/login'
import Detail from '../test/detail'
import Create from "../test/crete";
import Fenlei from "../test/fenlei";
import Shopping from "../test/shop";
import Search from "../test/search";


export default function Router() {

    let use = useParams()
    console.log(use)

    return (
        <BrowserRouter>
            {/* 使用 Routes 替换 Switch  */}
            <Routes>
                <Route path='/' element={<Home />} />
                <Route path='/zhuce' element={<Zhuce />} />
                <Route path='/login' element={<Login />} />
                <Route path='/detail/:id' element={<Detail />} />
                <Route path='/create/:value' element={<Create />} />
                <Route path='/fenlei/:value' element={<Fenlei />} />
                <Route path='/shopcart' element={<Shopping />} />
                <Route path='/search/:value' element={<Search />} />
            </Routes>
        </BrowserRouter>
    );
}

你可能感兴趣的:(react,react.js,javascript,前端)