feat(bridge): allow accessing injections from useNuxtApp (#1623)

This commit is contained in:
Daniel Roe 2021-11-02 09:45:44 +00:00 committed by GitHub
parent 47e0721413
commit 5aa33b807c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@ export default (ctx, inject) => {
mount: () => { },
provide: inject,
unmount: () => { },
use(vuePlugin) {
use (vuePlugin) {
vuePlugin.install(this)
},
version: Vue.version
@ -42,7 +42,16 @@ export default (ctx, inject) => {
nuxtApp.vue2App = this
})
setNuxtAppInstance(nuxtApp)
const proxiedApp = new Proxy(nuxtApp, {
get (target, prop) {
if (prop[0] === '$') {
return target.nuxt2Context[prop] || target.vue2App?.[prop]
}
return Reflect.get(target, prop)
}
})
inject('_nuxtApp', nuxtApp)
setNuxtAppInstance(proxiedApp)
inject('_nuxtApp', proxiedApp)
}