Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit bc6e119

Browse files
author
Philip Waritschlager
committed
change aysnc fetching method
1 parent 38e5075 commit bc6e119

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/entry-client.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,23 @@ if (window.__INITIAL_STATE__) {
3030
store.replaceState(window.__INITIAL_STATE__)
3131
}
3232

33-
// wait until router has resolved all async before hooks
34-
// and async components...
3533
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-
6134
// actually mount to DOM
6235
app.$mount('#app')
6336
})
6437

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+
6550
// service worker
6651
if ('https:' === location.protocol && navigator.serviceWorker) {
6752
navigator.serviceWorker.register('/service-worker.js')

0 commit comments

Comments
 (0)