UNPKG

923 BJavaScriptView Raw
1function createApp (AppClass) {
2 const app = new AppClass()
3 const weappAppConf = {
4 onLaunch (options) {
5 app.$app = this
6 app.$app.$router = app.$router = {
7 params: options
8 }
9 if (app.componentWillMount) {
10 app.componentWillMount()
11 }
12 if (app.componentDidMount) {
13 app.componentDidMount()
14 }
15 },
16
17 onShow (options) {
18 Object.assign(app.$router.params, options)
19 if (app.componentDidShow) {
20 app.componentDidShow()
21 }
22 },
23
24 onHide () {
25 if (app.componentDidHide) {
26 app.componentDidHide()
27 }
28 },
29
30 onError (err) {
31 if (app.componentDidCatchError) {
32 app.componentDidCatchError(err)
33 }
34 },
35
36 onPageNotFound (obj) {
37 if (app.componentDidNotFound) {
38 app.componentDidNotFound(obj)
39 }
40 }
41 }
42 return Object.assign(weappAppConf, app)
43}
44
45export default createApp