前端开发

项目准备

1.node环境

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

项目运行

git clone git@gitlab.jiangzheinfo.cn: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<any, any> {

    @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 (
            <SPeopleDiv>
                <div>姓名:{$people && $people.name}</div>
                <div>年龄:{$people && $people.age}</div>
                <div>性别:{$people && SexMap[$people.sex]}</div>
            </SPeopleDiv>
        );
    }
}

export default withRouter(Index);

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 因个人精力有限,暂停简书的维护,欢迎大家关注我的知乎https://www.zhihu.com/people/we...
    尾尾阅读 1,324评论 3 13
  • 摘要: 前端发展迅速,非常快! 原文:2018年前端开发回顾 作者:前端小智 Fundebug经授权转载,版权归原...
    Fundebug阅读 2,376评论 0 17
  • 前言:本文是转载文,前端发展发展迅速,非常的快。内容将回顾2018年一些重要的前端新闻,事件和 JavaScrip...
    强哥科技兴阅读 317评论 0 0
  • 前言 前端技术近几年发展十分迅速,各种框架层出不穷让人应接不暇,好不容易掌握了一个前端框架结果还没深入理解又出现了...
    奶爸码农阅读 6,954评论 0 32
  • 取名借鉴自:银河系漫游指南开源世界旅行手册 在业界,“前端研发”基本上等价于“Web 前端研发”,Wikipedi...
    WalkerJ阅读 813评论 0 0

友情链接更多精彩内容