mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
window.onNuxtReady is now a function
This commit is contained in:
parent
c92ac95371
commit
cb3bf4c320
@ -50,9 +50,9 @@ async function renderAndGetWindow (route) {
|
||||
})
|
||||
}
|
||||
// Used by nuxt.js to say when the components are loaded and the app ready
|
||||
window.onNuxtReady = function () {
|
||||
window.onNuxtReady(() => {
|
||||
resolve(window)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -222,6 +222,20 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m
|
||||
return Component
|
||||
})
|
||||
|
||||
// window.onNuxtReady(() => console.log('Ready')) hook
|
||||
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
|
||||
let _readyCbs = []
|
||||
window.onNuxtReady = function (cb) {
|
||||
_readyCbs.push(cb)
|
||||
}
|
||||
function nuxtReady (app) {
|
||||
_readyCbs.forEach((cb) => {
|
||||
if (typeof cb === 'function') {
|
||||
cb(app)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Promise.all(resolveComponents)
|
||||
.then((Components) => {
|
||||
const _app = new Vue(app)
|
||||
@ -233,10 +247,8 @@ Promise.all(resolveComponents)
|
||||
<% } %>
|
||||
// Hot reloading
|
||||
if (module.hot) hotReloadAPI(_app)
|
||||
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
|
||||
if (typeof window.onNuxtReady === 'function') {
|
||||
window.onNuxtReady(_app)
|
||||
}
|
||||
// Call window.onNuxtReady callbacks
|
||||
nuxtReady(_app)
|
||||
}
|
||||
<% if (store) { %>
|
||||
// Replace store state
|
||||
|
Loading…
Reference in New Issue
Block a user