fix(nuxt3): update legacy plugin (closes #1200)

This commit is contained in:
Pooya Parsa 2021-10-18 21:34:51 +02:00
parent d8d10febd5
commit 5e903ae176

View File

@ -123,8 +123,8 @@ const todo = new Set<keyof LegacyContext | keyof LegacyContext['ssrContext']>([
const routerKeys: Array<keyof LegacyContext | keyof LegacyContext['ssrContext']> = ['route', 'params', 'query']
export const legacyPlugin = (nuxt: NuxtApp) => {
nuxt._legacyContext = new Proxy(nuxt, {
export const legacyPlugin = (nuxtApp: NuxtApp) => {
nuxtApp._legacyContext = new Proxy(nuxtApp, {
get (nuxt, p: keyof LegacyContext | keyof LegacyContext['ssrContext']) {
// Unsupported keys
if (unsupported.has(p)) {
@ -137,7 +137,7 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
// vue-router implementation
if (routerKeys.includes(p)) {
if (!('$router' in nuxt)) {
if (!('$router' in nuxtApp)) {
return mock('vue-router is not being used in this project.')
}
switch (p) {
@ -170,12 +170,12 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
return nuxt.payload.data
}
if (p in nuxt.app) {
return nuxt.app[p]
if (p in nuxtApp.vueApp) {
return nuxtApp.vueApp[p]
}
if (p in nuxt) {
return nuxt[p]
if (p in nuxtApp) {
return nuxtApp[p]
}
return mock(`Accessing ${p} is not supported in Nuxt3.`)
@ -183,15 +183,15 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
}) as unknown as LegacyContext
if (process.client) {
nuxt.hook('app:created', () => {
const legacyApp = { ...nuxt.app } as LegacyApp
nuxtApp.hook('app:created', () => {
const legacyApp = { ...nuxtApp.vueApp } as LegacyApp
legacyApp.$root = legacyApp
// @ts-ignore
// TODO: https://github.com/nuxt/framework/issues/244
legacyApp.constructor = legacyApp
window[`$${nuxt.globalName}`] = legacyApp
window[`$${nuxtApp.globalName}`] = legacyApp
})
}
}