mpreact
react like framework for wechat mini program
usage for js
app.js
; @ // will be called after App.onLoad { this; } async { const res = await wx; // ... }
page.jsx
; ; ; @ /** content of page.wxml, jsx syntax */ template = <view class="container"> <Tabs tabs=thisstatetabs></Tabs> </view> ; // will be called after Page.onLoad { this }
component.jsx
; ; static propTypes = tabs: Array ; /** content of page.wxml, jsx syntax */ template = <view class="tabs"> <view wx_for=thispropstabs bindtap=thisselectTab data-index=index>item</view> <view>thisstateselectedTab</view> </view> ; // will be called after Component.attached { } { console } { this }
usage for ts
app.ts
; @ // will be called after App.onLoad { this; } async { const res = await wx; // ... }
page.tsx
; ; ; @<{} tabs: Array<string>> /** content of page.wxml, jsx syntax */ template = <view class="container"> <Tabs tabs=thisstatetabs></Tabs> </view> ; // will be called after Page.onLoad { this }
component.tsx
; ; <tabs: Array<string> selectedTab: string> /** content of page.wxml, jsx syntax */ template = <view class="tabs"> <view wx_for=thispropstabs bindtap=thisselectTab data-index=index>item</view> <view>thisstateselectedTab</view> </view> ; // will be called after Component.attached { } { console } { this }
api
### wx
promisified wx;
### page
-
state: Object;
-
query: Object; 页面参数;
-
setState(state: Partial<S>, cb?: Function): Promise
-
navigateTo(page: string, query?: { [key: string]: number | string | boolean }): Promise;
-
setTitle(title: string): Promise;
### component
-
props: Object;
-
state: Object;
-
setState(state: Partial<S>): Promise;