app.setup function in plugins #1667
-
Can someone explain to me the following and why this is necessary in plugins? I saw it in some shopware-pwa nuxt-plugins and have to to this in my own plugins, too. export default (context) => {
const app = context.app
const { setup } = app
app.setup = function (...args) {
let result = {}
if (setup instanceof Function) {
result = setup(...args) || {}
}
//CUSTOM CODE HERE
return result;
} How is this related to shopware-pwa, vue2/3 and/or nuxt? Is it shopware-pwa specific or a more general approach? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
it's more like Vue-related. Composables are supposed to work inside the setup method. When you want to do some additional stuff on every page and you want to use Nuxt plugin for that you would like to use So as a summary |
Beta Was this translation helpful? Give feedback.
-
@patzick Is it correct that this is not wortking anymore? I get the following error in combination with the new devTools. TypeError: Cannot read properties of undefined (reading 'addTimelineEvent')
at Object.log (composables.esm.js?58f0:2446)
at on (composables.esm.js?58f0:1223)
at app.setup (notifications.js?6341:22)
at app.setup (kippie-events.js?28be:18)
at app.setup (kippie-events.js?4fa7:18)
at mergedSetupFn (vue-composition-api.esm.js?a6f4:2098) |
Beta Was this translation helpful? Give feedback.
it's more like Vue-related. Composables are supposed to work inside the setup method. When you want to do some additional stuff on every page and you want to use Nuxt plugin for that you would like to use
global setup
. But, you're not the only one probably and just overwriting theglobal setup
you might break things. That's why first you're invoking the currentsetup
method, you get the response from that, doing your own logic and return the combined result of that action.So as a summary
You need to do this only if you're adding nuxt plugin and want to invoke some composables logic inside