From 13695db1c3bc44cb929f457cfd622526d1f4fbed Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 6 Jul 2021 14:34:20 -0400 Subject: [PATCH] update ` ``` -In addition, the awaited expression will be automatically wrapped with a `withAsyncContext` helper. The helper saves and restores the current instance context so that the current instance context is preserved even after the `await` statement: +In addition, the awaited expression will be automatically compiled in a format that preserves the current component instance context after the `await`: ```js import { withAsyncContext } from 'vue' export default { async setup() { - const post = await withAsyncContext( - fetch(`/api/post/1`).then((r) => r.json()) - ) + let __temp, __restore + + const post = + (([__temp, __restore] = withAsyncContext(() => + fetch(`/api/post/1`).then((r) => r.json()) + )), + (__temp = await __temp), + __restore(), + __temp) // current instance context preserved // e.g. onMounted() will still work. @@ -379,13 +377,13 @@ To explicitly expose properties in a ` ``` @@ -430,9 +428,9 @@ export default { setup() { const count = ref(0) return { - count, + count } - }, + } } ``` @@ -469,7 +467,7 @@ If you need to declare these options, use a separate normal ` @@ -490,7 +488,7 @@ This new scoping model will require tooling adjustments in two aspects: 1. IDEs will need to provide dedicated handling for this new ` ``` @@ -586,7 +584,7 @@ This object can then be passed to the template compiler: import { compile } from '@vue/compiler-dom' compile(template, { - bindingMetadata: bindings, + bindingMetadata: bindings }) ```