mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
fix(nuxt3): update legacy plugin (closes #1200)
This commit is contained in:
parent
d8d10febd5
commit
5e903ae176
@ -123,8 +123,8 @@ const todo = new Set<keyof LegacyContext | keyof LegacyContext['ssrContext']>([
|
|||||||
|
|
||||||
const routerKeys: Array<keyof LegacyContext | keyof LegacyContext['ssrContext']> = ['route', 'params', 'query']
|
const routerKeys: Array<keyof LegacyContext | keyof LegacyContext['ssrContext']> = ['route', 'params', 'query']
|
||||||
|
|
||||||
export const legacyPlugin = (nuxt: NuxtApp) => {
|
export const legacyPlugin = (nuxtApp: NuxtApp) => {
|
||||||
nuxt._legacyContext = new Proxy(nuxt, {
|
nuxtApp._legacyContext = new Proxy(nuxtApp, {
|
||||||
get (nuxt, p: keyof LegacyContext | keyof LegacyContext['ssrContext']) {
|
get (nuxt, p: keyof LegacyContext | keyof LegacyContext['ssrContext']) {
|
||||||
// Unsupported keys
|
// Unsupported keys
|
||||||
if (unsupported.has(p)) {
|
if (unsupported.has(p)) {
|
||||||
@ -137,7 +137,7 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
|
|||||||
|
|
||||||
// vue-router implementation
|
// vue-router implementation
|
||||||
if (routerKeys.includes(p)) {
|
if (routerKeys.includes(p)) {
|
||||||
if (!('$router' in nuxt)) {
|
if (!('$router' in nuxtApp)) {
|
||||||
return mock('vue-router is not being used in this project.')
|
return mock('vue-router is not being used in this project.')
|
||||||
}
|
}
|
||||||
switch (p) {
|
switch (p) {
|
||||||
@ -170,12 +170,12 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
|
|||||||
return nuxt.payload.data
|
return nuxt.payload.data
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p in nuxt.app) {
|
if (p in nuxtApp.vueApp) {
|
||||||
return nuxt.app[p]
|
return nuxtApp.vueApp[p]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p in nuxt) {
|
if (p in nuxtApp) {
|
||||||
return nuxt[p]
|
return nuxtApp[p]
|
||||||
}
|
}
|
||||||
|
|
||||||
return mock(`Accessing ${p} is not supported in Nuxt3.`)
|
return mock(`Accessing ${p} is not supported in Nuxt3.`)
|
||||||
@ -183,15 +183,15 @@ export const legacyPlugin = (nuxt: NuxtApp) => {
|
|||||||
}) as unknown as LegacyContext
|
}) as unknown as LegacyContext
|
||||||
|
|
||||||
if (process.client) {
|
if (process.client) {
|
||||||
nuxt.hook('app:created', () => {
|
nuxtApp.hook('app:created', () => {
|
||||||
const legacyApp = { ...nuxt.app } as LegacyApp
|
const legacyApp = { ...nuxtApp.vueApp } as LegacyApp
|
||||||
legacyApp.$root = legacyApp
|
legacyApp.$root = legacyApp
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// TODO: https://github.com/nuxt/framework/issues/244
|
// TODO: https://github.com/nuxt/framework/issues/244
|
||||||
legacyApp.constructor = legacyApp
|
legacyApp.constructor = legacyApp
|
||||||
|
|
||||||
window[`$${nuxt.globalName}`] = legacyApp
|
window[`$${nuxtApp.globalName}`] = legacyApp
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user