Skip to content

Commit cf83e29

Browse files
committed
more updates per feedback
1 parent 4a37fe0 commit cf83e29

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

src/api/directives.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,11 @@
464464
</ul>
465465
```
466466

467+
Since 3.2, you can also memoize part of the template with invalidation conditions using [`v-memo`](#v-memo).
468+
467469
- **See also:**
468470
- [Data Binding Syntax - interpolations](../guide/template-syntax.html#text)
471+
- [v-memo](#v-memo)
469472

470473
## v-memo <Badge text="3.2+" />
471474

@@ -483,7 +486,7 @@
483486

484487
When the component re-renders, if both `valueA` and `valueB` remain the same, all updates for this `<div>` and its children will be skipped. In fact, even the Virtual DOM VNode creation will also be skipped since the memoized copy of the sub-tree can be reused.
485488

486-
It is important to specify the memoization array correctly, otherwise we may skip updates that should indeed be applied.
489+
It is important to specify the memoization array correctly, otherwise we may skip updates that should indeed be applied. `v-memo` with an empty dependency array (`v-memo="[]"`) would be functionally equivalent to `v-once`.
487490

488491
This directive is provided solely for micro optimizations in performance-critical scenarios and should be rarely needed. The most common case where this may prove helpful is when rendering large `v-for` lists (where `length > 1000`):
489492

@@ -498,6 +501,9 @@
498501

499502
`v-memo` can also be used on components to manually prevent unwanted updates in certain edge cases where the child component update check has been de-optimized. But again, it is the developer's responsibility to specify correct dependency arrays to avoid skipping necessary updates.
500503

504+
- **See also:**
505+
- [v-once](#v-once)
506+
501507
## v-is <Badge text="deprecated" type="warning" />
502508

503509
Deprecated in 3.1.0. Use [`is` attribute with `vue:` prefix](/api/special-attributes.html#is) instead.

src/api/global-api.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,11 @@ customElements.define('my-vue-element', MyVueElement)
265265

266266
// You can also programmatically instantiate the element:
267267
// (can only be done after registration)
268-
document.body.appendChild(new MyVueElement({
269-
// initial props (optional)
270-
}))
268+
document.body.appendChild(
269+
new MyVueElement({
270+
// initial props (optional)
271+
})
272+
)
271273
```
272274

273275
For more details on building Web Components with Vue, especially with Single File Components, see [Vue and Web Components](/guide/web-components.html#building-custom-elements-with-vue).
@@ -565,7 +567,7 @@ export default {
565567
</style>
566568
```
567569

568-
For more information about using CSS modules, see [Vue Loader - CSS Modules](https://vue-loader.vuejs.org/guide/css-modules.html).
570+
For more information about using CSS modules, see [SFC Style Features: `<style module>`](/api/sfc-style.html#style-module).
569571

570572
### Arguments
571573

src/api/sfc-script-setup.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ To explicitly expose properties in a `<script setup>` component, use the `define
148148

149149
```vue
150150
<script setup>
151+
import { ref } from 'vue'
152+
151153
const a = 1
152154
const b = ref(2)
153155
@@ -212,6 +214,10 @@ const post = await fetch(`/api/post/1`).then(r => r.json())
212214

213215
In addition, the awaited expression will be automatically compiled in a format that preserves the current component instance context after the `await`.
214216

217+
:::warning Note
218+
`async setup()` must be used in combination with `Suspense`, which is currently still an experimental feature. We plan to finalize and document it in a future release - but if you are curious now, you can refer to its [tests](https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/__tests__/components/Suspense.spec.ts) to see how it works.
219+
:::
220+
215221
## TypeScript-only Features
216222

217223
### Type-only props/emit declarations
@@ -236,7 +242,7 @@ const emit = defineEmits<{
236242

237243
- In dev mode, the compiler will try to infer corresponding runtime validation from the types. For example here `foo: String` is inferred from the `foo: string` type. If the type is a reference to an imported type, the inferred result will be `foo: null` (equal to `any` type) since the compiler does not have information of external files.
238244

239-
- In prod mode, the compiler will generate the array format declaration to reduce bundle size (the props here will be compiled into `['msg']`)
245+
- In prod mode, the compiler will generate the array format declaration to reduce bundle size (the props here will be compiled into `['foo', 'bar']`)
240246

241247
- The emitted code is still TypeScript with valid typing, which can be further processed by other tools.
242248

@@ -254,10 +260,12 @@ One drawback of the type-only `defineProps` declaration is that it doesn't have
254260
```ts
255261
interface Props {
256262
msg?: string
263+
labels?: string[]
257264
}
258265

259266
const props = withDefaults(defineProps<Props>(), {
260-
msg: 'hello'
267+
msg: 'hello',
268+
labels: () => ['one', 'two']
261269
})
262270
```
263271

src/api/sfc-style.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ You can customize the property key of the injected classes object by giving the
144144
</style>
145145
```
146146

147+
### Usage with Composition API
148+
149+
The injected classes can be accessed in `setup()` and `<script setup>` via the [`useCssModule`](/api/global-api.html#usecssmodule) API. For `<style module>` blocks with custom injection names, `useCssModule` accepts the matching `module` attribute value as the first argument:
150+
151+
```js
152+
// default, returns classes for <style module>
153+
useCssModule()
154+
155+
// named, returns classes for <style module="classes">
156+
useCssModule('classes')
157+
```
158+
147159
## State-Driven Dynamic CSS
148160

149161
SFC `<style>` tags support linking CSS values to dynamic component state using the `v-bind` CSS function:

0 commit comments

Comments
 (0)