From 2418a4a27c684cfcb04d951e8df47f0e6eaf8271 Mon Sep 17 00:00:00 2001 From: ubugeeei Date: Wed, 16 Sep 2026 14:34:08 +0900 Subject: [PATCH 1/3] docs: add RFC 823 patterned template reference guide --- src/api/built-in-directives.md | 20 +++ src/guide/essentials/conditional.md | 2 + src/guide/essentials/patterned-templates.md | 160 ++++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 src/guide/essentials/patterned-templates.md diff --git a/src/api/built-in-directives.md b/src/api/built-in-directives.md index 57ad4dd055..8b580801be 100644 --- a/src/api/built-in-directives.md +++ b/src/api/built-in-directives.md @@ -1,5 +1,25 @@ # Built-in Directives {#built-in-directives} +## v-match (RFC Reference Implementation) {#v-match} + +These directives are proposed in [RFC #823](https://github.com/vuejs/rfcs/pull/823). They are available only in its Draft reference implementation, not in a released Vue version. + +- **`v-match` expects:** a subject expression. +- **Shorthand, arguments, and modifiers:** none. + +`v-match` evaluates one subject and selects the first matching direct `v-when` child. Patterns support literals, values, objects, arrays, `_`, `const` bindings, rest, `|` alternatives, parentheses, and `as` bindings. Bindings are local to the selected arm. The reference type checker requires exhaustive coverage by default. + +See [Branching on One Value](/guide/essentials/patterned-templates) for syntax, binding scopes, rest types, guards, placement rules, and coverage diagnostics. + +## v-when (RFC Reference Implementation) {#v-when} + +Declares a direct arm of [`v-match`](#v-match) in the [Draft reference implementation of RFC #823](https://github.com/vuejs/rfcs/pull/823). + +- **Expects:** a pattern, optionally followed by `if (guard)`. +- **Shorthand, arguments, and modifiers:** none. + +The first matching arm renders. Pattern bindings are available to its guard, props, directives, event handlers, and children. Use an unguarded `_` as the final fallback, or enumerate every case. See [Branching on One Value](/guide/essentials/patterned-templates). + ## v-text {#v-text} Update the element's text content. diff --git a/src/guide/essentials/conditional.md b/src/guide/essentials/conditional.md index a1b507a6a7..1cf60fe13f 100644 --- a/src/guide/essentials/conditional.md +++ b/src/guide/essentials/conditional.md @@ -1,5 +1,7 @@ # Conditional Rendering {#conditional-rendering} +For the proposed `v-match` / `v-when` syntax, see [Branching on One Value](./patterned-templates). That page describes the Draft reference implementation of RFC #823; the feature has not been accepted or released. +
diff --git a/src/guide/essentials/patterned-templates.md b/src/guide/essentials/patterned-templates.md new file mode 100644 index 0000000000..b99d9c30be --- /dev/null +++ b/src/guide/essentials/patterned-templates.md @@ -0,0 +1,160 @@ +# Branching on One Value {#branching-on-one-value} + +::: warning RFC Reference Implementation +This page documents the **Draft reference implementation** of [RFC #823](https://github.com/vuejs/rfcs/pull/823). Patterned templates are proposed syntax, not an accepted or released Vue feature. Trying these examples requires the compiler and language-tools reference branches linked from the RFC. The syntax and implementation can change as the RFC is discussed. +::: + +A loading screen often renders different content for the states of one request. With `v-if`, each branch repeats the value it inspects. The proposed `v-match` directive groups those branches around a single expression: + +```vue + + + +``` + +`v-match` evaluates `request` once. Its direct children use `v-when` to describe the values they accept. Vue checks them in source order and renders the first matching branch. There is no fallthrough. + +The `