entry-client.js
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import 'babel-polyfill';
import Vue from 'vue';
import {
ROUTE_CHANGE,
PAGE_INIT_VISIBLE,
} from 'store/yoho/types';
import FastClick from 'fastclick';
import {createApp} from './app';
import {createApi} from 'create-api';
import {createYoRouter} from 'common/router.js';
import yoho from '../public/js/yoho';
import message from 'components/message';
import 'statics/scss/common.scss';
import 'statics/scss/animation.scss';
import 'statics/font/iconfont.css';
import 'statics/scss/font.scss';
FastClick.attach(document.body);
const {app, router, store} = createApp();
if (window.__INITIAL_STATE__) {
store.replaceState(window.__INITIAL_STATE__);
}
Vue.prop('yoho', yoho);
Vue.prop('message', message);
Vue.prop('bus', new Vue());
Vue.prop('api', createApi());
Vue.prop('yoRouter', createYoRouter(router, store));
document.addEventListener('visibilitychange', function() {
if (document.visibilityState === 'visible') {
store.commit(PAGE_INIT_VISIBLE, {visible: false});
setTimeout(() => {
store.commit(PAGE_INIT_VISIBLE, {visible: true});
}, 500);
}
});
router.onReady(() => {
router.beforeResolve((to, from, next) => {
const matched = router.getMatchedComponents(to);
store.commit(ROUTE_CHANGE, to);
Promise.all(matched.map(({asyncData}) =>
asyncData && asyncData({store, router: to})))
.then(() => {
if (!yoho.isAndroid || store.state.yoho.visible) {
return next();
} else {
history.pushState({}, '', from.fullPath);
}
})
.catch(next);
});
app.$mount('#app');
});