前端開發(fā)

項目準備

1.node環(huán)境

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

項目運行

git clone git@gitlab.jiangzheinfo.cn:weixin-web/weixin-sample.git
npm install
npm start

功能開發(fā)

返回的用戶信息用于展示

{
  "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;
  }
`;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 因個人精力有限,暫停簡書的維護,歡迎大家關(guān)注我的知乎https://www.zhihu.com/people/we...
    尾尾閱讀 1,321評論 3 13
  • 摘要: 前端發(fā)展迅速,非常快! 原文:2018年前端開發(fā)回顧 作者:前端小智 Fundebug經(jīng)授權(quán)轉(zhuǎn)載,版權(quán)歸原...
    Fundebug閱讀 2,370評論 0 17
  • 前言:本文是轉(zhuǎn)載文,前端發(fā)展發(fā)展迅速,非常的快。內(nèi)容將回顧2018年一些重要的前端新聞,事件和 JavaScrip...
    強哥科技興閱讀 317評論 0 0
  • 前言 前端技術(shù)近幾年發(fā)展十分迅速,各種框架層出不窮讓人應(yīng)接不暇,好不容易掌握了一個前端框架結(jié)果還沒深入理解又出現(xiàn)了...
    奶爸碼農(nóng)閱讀 6,954評論 0 32
  • 取名借鑒自:銀河系漫游指南開源世界旅行手冊 在業(yè)界,“前端研發(fā)”基本上等價于“Web 前端研發(fā)”,Wikipedi...
    WalkerJ閱讀 812評論 0 0

友情鏈接更多精彩內(nèi)容