用react+redux编写一个页面小demo

初步目录结构

整体目录结构

这里写图片描述

src目录结构

这里写图片描述

entry 存放页面的入口文件

src 页面的源文件

static 页面源文件打包后生成的文件

webpack webpack打包文件

package.json package.json文件

.babelrc 支持es6语法

其中 src 中子目录结构如下:

components 页面组件

constants 页面需要用到的一些常量

helpers 工具方法

mock 模拟json数据

redux redux数据控制目录

views 页面视图文件,主要视图全在这个文件

react配合redux编写页面流程

entry/hello.js
import React from 'react';
import { render } from 'react-dom';
import HelloPage from '../src/views/HelloPage';

import helloStore from '../src/redux/stores/helloStore';
import { Provider } from 'react-redux';

render(
    <Provider store={helloStore}>
        <HelloPage />
    </Provider>,
    document.getElementById('hello')
);

HelloPage.jsx是视图文件,通过react-redux中的Providerstore绑定到视图中

src/redux/actions/helloAction.js
import fetch from 'isomorphic-fetch';

// 纯事件定义
export const ADD_COUNT = 'ADD_COUNT';
export const ADD_PERSON = 'ADD_PERSON';
export const DELETE_PERSON = 'DELETE_PERSON';

// async
// 异步的请求定义
export const FETCH_START = 'FETCH_START';
export const FETCH_SUCCESS = 'FETCH_SUCCESS';
export const FETCH_FAUILE = 'FETCH_FAUILE';

// pure functions
export function addCount() {
   
    return {
        type : ADD_COUNT
    }
}

export function addPerson(person) {
   
    return {
        type : ADD_PERSON,
        person
    }
  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值