This repository was archived by the owner on Apr 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-27
lines changed Expand file tree Collapse file tree 1 file changed +12
-27
lines changed Original file line number Diff line number Diff line change @@ -30,38 +30,23 @@ if (window.__INITIAL_STATE__) {
30
30
store . replaceState ( window . __INITIAL_STATE__ )
31
31
}
32
32
33
- // wait until router has resolved all async before hooks
34
- // and async components...
35
33
router . onReady ( ( ) => {
36
- // Add router hook for handling asyncData.
37
- // Doing it after initial route is resolved so that we don't double-fetch
38
- // the data that we already have. Using router.beforeResolve() so that all
39
- // async components are resolved.
40
- router . beforeResolve ( ( to , from , next ) => {
41
- const matched = router . getMatchedComponents ( to )
42
- const prevMatched = router . getMatchedComponents ( from )
43
- let diffed = false
44
- const activated = matched . filter ( ( c , i ) => {
45
- return diffed || ( diffed = ( prevMatched [ i ] !== c ) )
46
- } )
47
- const asyncDataHooks = activated . map ( c => c . asyncData ) . filter ( _ => _ )
48
- if ( ! asyncDataHooks . length ) {
49
- return next ( )
50
- }
51
-
52
- bar . start ( )
53
- Promise . all ( asyncDataHooks . map ( hook => hook ( { store, route : to } ) ) )
54
- . then ( ( ) => {
55
- bar . finish ( )
56
- next ( )
57
- } )
58
- . catch ( next )
59
- } )
60
-
61
34
// actually mount to DOM
62
35
app . $mount ( '#app' )
63
36
} )
64
37
38
+ Vue . mixin ( {
39
+ beforeMount ( ) {
40
+ const { asyncData } = this . $options
41
+ if ( asyncData ) {
42
+ this . dataPromise = asyncData ( {
43
+ store : this . $store ,
44
+ route : this . $route
45
+ } )
46
+ }
47
+ }
48
+ } )
49
+
65
50
// service worker
66
51
if ( 'https:' === location . protocol && navigator . serviceWorker ) {
67
52
navigator . serviceWorker . register ( '/service-worker.js' )
You can’t perform that action at this time.
0 commit comments