mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
Add window.onNuxtReady before plugins
This commit is contained in:
parent
78a2c5afe7
commit
48c544b106
@ -222,20 +222,14 @@ 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) => {
|
||||
window._nuxtReadyCbs.forEach((cb) => {
|
||||
if (typeof cb === 'function') {
|
||||
cb(app)
|
||||
}
|
||||
})
|
||||
// Add router hooks
|
||||
router.afterEach(function (to) {
|
||||
router.afterEach(function (to, from) {
|
||||
app.$nuxt.$emit('routeChanged', to, from)
|
||||
})
|
||||
}
|
||||
|
@ -21,6 +21,15 @@ Vue.use(Meta, {
|
||||
tagIDKeyName: 'hid' // the property name that vue-meta uses to determine whether to overwrite or append a tag
|
||||
})
|
||||
|
||||
if (process.BROWSER_BUILD) {
|
||||
// window.onNuxtReady(() => console.log('Ready')) hook
|
||||
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
|
||||
window._nuxtReadyCbs = []
|
||||
window.onNuxtReady = function (cb) {
|
||||
window._nuxtReadyCbs.push(cb)
|
||||
}
|
||||
}
|
||||
|
||||
// Includes external plugins
|
||||
<% plugins.forEach(function (pluginPath) { %>
|
||||
require('<%= pluginPath %>')
|
||||
|
Loading…
Reference in New Issue
Block a user