前端开发

项目准备

1.node环境

2.react + typescript + antd + webpack + mobx + inversify + styled-components

  • https://ant.design/index-cn
  • https://cn.mobx.js.org/
  • https://www.styled-components.com/

项目运行

git clone [email protected]:weixin-web/weixin-sample.git
npm install
npm start

功能开发

返回的用户信息用于展示

{
  "code": 200,
  "msg": "获取成功",
  "data": {
    "name": "张三",
    "age": 22,
    "sex": 1
  }
}

1.定义Service

@bean($PeopleService)
export class $PeopleService {

    public getInfo = () => {
        return AjaxUtils.post('/demo', {})
    };

}

2.定义Bean

@bean($People)
export class $People extends $BaseEntity {
    @observable
    public name: string;
    @observable
    public age: number;
    @observable
    public sex: Sex;
}

3.定义MV

@bean($PeopleMV)
export class $PeopleMV {

    @autowired($PeopleService)
    public $peopleService: $PeopleService;

    @observable
    public $people: $People;

    @action
    public getInfo = () => {
        this.$peopleService.getInfo()
            .then(responseHelper)
            .then(data => this.$people = new $People(data))
    }
}

4.UI组件渲染

@observer
class Index extends React.Component {

    @autowired($Theme)
    public $theme: $Theme;

    @autowired($PeopleMV)
    public $peopleMV: $PeopleMV;

    constructor(props) {
        super(props);
        this.state = {};
    }

    public componentDidMount() {
        this.$peopleMV.getInfo();
    }

    public render() {
        const { $people } = this.$peopleMV;
        return (
            
                
姓名:{$people && $people.name}
年龄:{$people && $people.age}
性别:{$people && SexMap[$people.sex]}
); } } export default withRouter(Index);

5.样式组件styled-components简单使用

const SPeopleDiv = styled.div`// styled
  & {
    position: relative;
    padding: 0.3rem;
    line-height: 2;
  }
`;

你可能感兴趣的:(前端开发)