All Projects → foolsogood → mall-by-react

foolsogood / mall-by-react

Licence: other
一个react商城客户端和egg服务端

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to mall-by-react

z
基于 MidwayJS(EggJS) + TypeScript 的多模块应用 [ NodeJS 版 ]
Stars: ✭ 122 (+454.55%)
Mutual labels:  sequelize, egg, midway
dva-boot
🌱 使用CRA(create-react-app v2) 构建的react dva 2 脚手架 支持动态路由、接口数据模拟、按功能分层、并且包含诸多实用的小组件
Stars: ✭ 79 (+259.09%)
Mutual labels:  dva, react-router-v4
Jsyang Admin
基于nodejs+egg+squelize+mysql+antd-design+wangEditor+dva+umi+react开发的后台管理平台快速生成方案,让前端er也可以快速进行全栈开发 https://jsyangadmin.github.io/
Stars: ✭ 29 (+31.82%)
Mutual labels:  dva, egg
Egg Restapi Module Tool
a example of eggjs, react, antd, dva, webpack, mysql, restful api and other stuff made it work...
Stars: ✭ 332 (+1409.09%)
Mutual labels:  dva, egg
React Blog
react hooks + koa2 + sequelize + mysql 构建的个人博客。具备评论、通知、上传文章等等功能
Stars: ✭ 530 (+2309.09%)
Mutual labels:  sequelize, react-router-v4
React Antd Admin
后台前端管理系统,基于react、typescript、antd、dva及一些特别优秀的开源库实现
Stars: ✭ 117 (+431.82%)
Mutual labels:  dva, react-router-v4
egg-nideshop
使用egg框架重写的nideshop后台
Stars: ✭ 49 (+122.73%)
Mutual labels:  sequelize, egg
Egg Commerce
Stars: ✭ 264 (+1100%)
Mutual labels:  sequelize, egg
Egg 24time
A Twitter-like news and social server for Egg. 微信小程序社区全栈解决方案
Stars: ✭ 493 (+2140.91%)
Mutual labels:  sequelize, egg
Egg Sequelize
Sequelize for Egg.js
Stars: ✭ 540 (+2354.55%)
Mutual labels:  sequelize, egg
mtime
🍳 A website use mTime api (egg)
Stars: ✭ 57 (+159.09%)
Mutual labels:  egg
Express-REST-API-Generator
Express REST API Generator is an Express Based API skeleton. A template for starting projects with express as an API. This project can be used for creating a RESTful API using Node JS, Express as the framework, Mongoose to interact with a MongoDB instance and Sequelize for support of SQL compatible databases. Mocha is also used for running unit …
Stars: ✭ 100 (+354.55%)
Mutual labels:  sequelize
universal-react-redux-typescript-starter-kit
A minimal starter kit with React, Redux, server side rendering, hot reloading, and Webpack 2. 100% TypeScript.
Stars: ✭ 12 (-45.45%)
Mutual labels:  react-router-v4
rogue.js
The "nearly invisible" way to server-render React applications
Stars: ✭ 1,914 (+8600%)
Mutual labels:  react-router-v4
egg-weapp-sdk
Egg的微信小程序登录会话管理SDK
Stars: ✭ 111 (+404.55%)
Mutual labels:  egg
graphql-sequelize-generator
A Graphql API generator based on Sequelize.
Stars: ✭ 20 (-9.09%)
Mutual labels:  sequelize
DRIP
Fixed Income Analytics, Portfolio Construction Analytics, Transaction Cost Analytics, Counter Party Analytics, Asset Backed Analytics
Stars: ✭ 44 (+100%)
Mutual labels:  dva
doc
Sequelize Documentation
Stars: ✭ 32 (+45.45%)
Mutual labels:  sequelize
node-sequelize
nodejs使用sequelize的api测试应用
Stars: ✭ 29 (+31.82%)
Mutual labels:  sequelize
react-native-dva-starter-with-builtin-router
Integrate dva into react-native app with builtin router of dva.
Stars: ✭ 17 (-22.73%)
Mutual labels:  dva

客户端

部分页面预览

首页 分类 购物车 购物车 详情 评论

usage

  • 1.如果不需要egg服务端,可使用前端mock命令提供数据,只支持get
     yarn mock  or npm run mock
    
  • 2.使用midway做服务端 将config/config.default.ts 中 redis,sequelize等修改为自己本地配置, yarn dev 即可

tips

首先,这是一个react新手写的练手项目,有不对的地方请包涵(2017.08)。
现client-use-dva已用typescript重构(2019.5)
这是用react写的一个商城,比较简单。脚手架采用create-react-app。ui采用antd。 技术栈:react,react-router v4,dva等。 写这个过程中遇到的一些重难点(或者是踩过的坑比较贴切),只贴关键代码:

reacr-router v4。

  • 1.路由传值
    在路由配置中注入 history,然后把参数写在Route组件中
 <Route path="/goodDetail/:goodId" component={GoodDetail} />

在页面中用组件传值:

   <Link to={`/goodDetail/${good.goodId}`}>

在事件中传值

1.引入 import PropTypes from 'prop-types',
2.声明router类型 static contextTypes = {
       router: PropTypes.object
 };
3.this.context.router.history.push({
           pathname: '/goodDetail',
           query:{
             cateId:xxx,
             goodId:xxx
           }
       })

- 2.路由获取参数
在componentDidMount函数中 let {goodId} = this.props.match.params
- 3.获取当前路由路径
window.location.pathname

结合生命周期可以做的一些事

如果在componentDidMount添加了一些事件监听或者定时器之类的,要在componentWillUnmount里面清掉它们。如果是有一些setState操作的还要格外注意,因为setState是异步的,离开当前组件时不一定能马上消除掉事件监听或者定时器的影响,可以添加一个变量为false,在componentWillUnmount里面把它改为true,每次setState之前都要判断该变量,为false才能操作之类(详细可看首页相关)

循环渲染

如果我要渲染的是一个集合goodList,可以这样

Object.keys(goodList).map((item)=>{
  return (
    <div key={goodList[item].goodId}>.....</div>
  )<br/>
})

而不是一定要拿到数组才能渲染,key的话最好不要用索引,而是用一些商品id,用户id之类

状态管理

    1. 使用dva

路由按需加载

使用react-loadable

import Loadable from 'react-loadable';
const Home=Loadable({
    loader:()=>import('views/home'),
    loading: Loading,
})
  <Route exact path="/" component={Home} />

高阶组件

项目中使用装饰器连接高阶组件更优雅 如dva的connect和mobx中的observer以及页面布局使用的公共组件WithFooter WithHeader等

@connect
@WithFooter
class Home extends Component {}

组件通信

使用node 的event模块的EventEmitter类可满足一般的父子组件或兄弟组件通信

TODO hook重写


服务端

框架采用midway,数据库 mysql,orm用sequelize-typescript,后端缓存用 redis
主要实现如下接口:登录注册、获取各分类商品、商品查询、商品评论、商品收藏、提交订单和订单查询、上传头像或图片、绑定手机、发送短信验证码等

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].