daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const store = createStore()
  2.  
  3. // data populated from server
  4. store.replaceState(window.__INITIAL_STATE__)
  5. const router = createRouter()
  6.  
  7. const routerReady = new Promise(resolve => {
  8.   router.onReady(resolve)
  9. }).then(() => {
  10.   router.getMatchedComponents(router.currentRoute).forEach(component => {
  11.     if (component.lazyData) {
  12.       component.lazyData(store, router.currentRoute, {})
  13.     }
  14.   })
  15.  
  16.   router.beforeResolve((to, from, next) => {
  17.     const matched = router.getMatchedComponents(to)
  18.     const permissionPromises = matched.map(component => {
  19.       if (component.permissions) {
  20.         return component.permissions(store, to, from)
  21.       }
  22.       return Promise.resolve()
  23.     })
  24.  
  25.     Promise.all(permissionPromises)
  26.       .then(() => {
  27.         next()
  28.       })
  29.       .catch(err => {
  30.         console.log(err)
  31.         next(err)
  32.       })
  33.   })
  34.  
  35.   router.afterEach((to, from) => {
  36.     const matched = router.getMatchedComponents(to)
  37.  
  38.     matched.forEach(component => {
  39.       if (component.criticalData) {
  40.         component.criticalData(store, to, from)
  41.       }
  42.     })
  43.  
  44.     matched.forEach(component => {
  45.       if (component.lazyData) {
  46.         component.lazyData(store, to, from)
  47.       }
  48.     })
  49.   })
  50. })
  51.  
  52. const app = createApp(store, router)
  53. routerReady.then(() => {
  54.   app.$mount('#app')
  55. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top