mirror of https://github.com/vuejs/core.git
fix(runtime-core): support for nested calls to runWithContext (#10261)
close #10260
This commit is contained in:
parent
eb1b9116d7
commit
75e02b5099
|
@ -123,6 +123,13 @@ describe('api: createApp', () => {
|
|||
|
||||
expect(app.runWithContext(() => inject('foo'))).toBe(1)
|
||||
|
||||
expect(
|
||||
app.runWithContext(() => {
|
||||
app.runWithContext(() => {})
|
||||
return inject('foo')
|
||||
}),
|
||||
).toBe(1)
|
||||
|
||||
// ensure the context is restored
|
||||
inject('foo')
|
||||
expect('inject() can only be used inside setup').toHaveBeenWarned()
|
||||
|
|
|
@ -387,11 +387,12 @@ export function createAppAPI<HostElement>(
|
|||
},
|
||||
|
||||
runWithContext(fn) {
|
||||
const lastApp = currentApp
|
||||
currentApp = app
|
||||
try {
|
||||
return fn()
|
||||
} finally {
|
||||
currentApp = null
|
||||
currentApp = lastApp
|
||||
}
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue