mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +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
|
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) {
|
function nuxtReady (app) {
|
||||||
_readyCbs.forEach((cb) => {
|
window._nuxtReadyCbs.forEach((cb) => {
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
cb(app)
|
cb(app)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Add router hooks
|
// Add router hooks
|
||||||
router.afterEach(function (to) {
|
router.afterEach(function (to, from) {
|
||||||
app.$nuxt.$emit('routeChanged', 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
|
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
|
// Includes external plugins
|
||||||
<% plugins.forEach(function (pluginPath) { %>
|
<% plugins.forEach(function (pluginPath) { %>
|
||||||
require('<%= pluginPath %>')
|
require('<%= pluginPath %>')
|
||||||
|
Loading…
Reference in New Issue
Block a user