I think you can create a plugin or component and import in all of your layouts.
I thought about using plugin but it seems there no way to do what I wanted. The closest option is to use a mixin and define a mounted hook but that will apply to all components. If you could give me an example, that would be very appreciated.
And I don't understand component and import in all of your layouts.. Could you elaborate in more details?
Thanks
Hi @zzhjerry,
Can you give us more information about what you would like to achieve in the global mounted function?
Workaround for googlers:
1) Create file utils/extend-vue-app.js:
export default function extend (app, mixin) {
if (!app.mixins) {
app.mixins = []
}
app.mixins.push(mixin)
}
2) Create plugins/foo.js:
import extend from 'utils/extend-vue-app'
export default async function ({ app }) {
extend(app, {
mounted () {
console.log('Hooray, Nuxt.js app mounted.')
},
})
}
3) Load your new plugin in nuxt.config.js:
module.exports = {
...
plugins: [
...
'~/plugins/foo.js',
],
}
@alexchopin I use this for all kinds of things:
vue-stash)@IlyaSemenov , thanks
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Workaround for googlers:
1) Create file
utils/extend-vue-app.js:2) Create
plugins/foo.js:3) Load your new plugin in
nuxt.config.js:@alexchopin I use this for all kinds of things:
vue-stash)