Skip to content

Commit f3ed81b

Browse files
committed
Merge branch 'main' of https://github.com/vuejs/docs
2 parents d123362 + 05c75f6 commit f3ed81b

File tree

17 files changed

+111
-32
lines changed

17 files changed

+111
-32
lines changed

.vitepress/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import fs from 'fs'
22
import path from 'path'
33
import { defineConfigWithTheme } from 'vitepress'
4+
import type { Config as ThemeConfig } from '@vue/theme'
45
import baseConfig from '@vue/theme/config'
56
import { headerPlugin } from './headerMdPlugin'
6-
import type { Config } from '@vue/theme'
7-
import { UserConfig } from 'vitepress'
87

98
const nav = [
109
{
@@ -531,8 +530,8 @@ export const sidebar = {
531530
]
532531
}
533532

534-
export default defineConfigWithTheme<Config>({
535-
extends: baseConfig as () => UserConfig<Config>,
533+
export default defineConfigWithTheme<ThemeConfig>({
534+
extends: baseConfig,
536535

537536
lang: 'en-US',
538537
title: 'Vue.js',
@@ -571,6 +570,7 @@ export default defineConfigWithTheme<Config>({
571570
{
572571
src: 'https://cdn.usefathom.com/script.js',
573572
'data-site': 'XNOLWPLB',
573+
'data-spa': 'auto',
574574
defer: ''
575575
}
576576
]

.vitepress/theme/components/PreferenceSwitch.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { VTSwitch, VTIconChevronDown } from '@vue/theme'
33
import { useRoute } from 'vitepress'
4-
import { ref, computed, inject, Ref } from 'vue'
4+
import { inject, Ref } from 'vue'
55
import {
66
preferCompositionKey,
77
preferComposition,
@@ -10,17 +10,15 @@ import {
1010
} from './preferences'
1111
1212
const route = useRoute()
13-
const show = computed(() =>
13+
const show = $computed(() =>
1414
/^\/(guide|tutorial|examples)\//.test(route.path)
1515
)
16-
const showSFC = computed(() => !/^\/guide/.test(route.path))
17-
const isOpen = ref(
18-
typeof localStorage !== 'undefined' &&
19-
!localStorage.getItem(preferCompositionKey)
20-
)
16+
const showSFC = $computed(() => !/^\/guide/.test(route.path))
17+
18+
let isOpen = $ref(true)
2119
2220
const toggleOpen = () => {
23-
isOpen.value = !isOpen.value
21+
isOpen = !isOpen
2422
}
2523
2624
const removeOutline = (e: Event) => {

src/api/composition-api-lifecycle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Registers a callback to be called after the component has been unmounted.
115115

116116
```vue
117117
<script setup>
118-
import { onMounted, unUnmounted } from 'vue'
118+
import { onMounted, onUnmounted } from 'vue'
119119
120120
let intervalId
121121
onMounted(() => {

src/api/options-rendering.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## template
44

5-
A string template for the component instance.
5+
A string template for the component.
66

77
- **Type**
88

@@ -14,13 +14,13 @@ A string template for the component instance.
1414

1515
- **Details**
1616

17-
Template provided via the `template` option will be compiled on-the-fly, therefore it is only supported when using the full build (i.e. the standalone `vue.js` that can compile templates in the browser).
18-
19-
The template will **replace** the `innerHTML` of mounted element. Any existing markup inside the mounted element will be ignored.
17+
A template provided via the `template` option will be compiled on-the-fly at runtime. It is only supported when using a full build of Vue that includes the template compiler. The builds that include the template compiler have the word `runtime` in their names, e.g. `vue.runtime.esm-bundler.js`. Consult the [dist file guide](https://github.com/vuejs/core/tree/main/packages/vue#which-dist-file-to-use) for more details about the different builds.
2018

2119
If the string starts with `#` it will be used as a `querySelector` and use the selected element's `innerHTML` as the template string. This allows the source template to be authored using native `<template>` elements.
2220

23-
If the `render` is also present in the same component, `template` will be ignored.
21+
If the `render` option is also present in the same component, `template` will be ignored.
22+
23+
If the root component of your application doesn't have a `template` or `render` option specified, Vue will try to use the `innerHTML` of the mounted element as the template instead.
2424

2525
:::warning Security Note
2626
Only use template sources that you can trust. Do not use user-provided content as your template. See [Security Guide](/guide/best-practices/security.html#rule-no-1-never-use-non-trusted-templates) for more details.

src/api/options-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Declare the props of a component.
7878
7979
- **Details**
8080
81-
In Vue, all component props need to be explicit declared. Component props can be declared in two forms:
81+
In Vue, all component props need to be explicitly declared. Component props can be declared in two forms:
8282
8383
- Simple form using an array of strings
8484
- Full form using an object where each property key is the name of the prop, and the value is the prop's type (a constructor function) or advanced options.

src/api/sfc-script-setup.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,31 @@ import * as Form from './form-components'
127127
</template>
128128
```
129129

130+
## Using Custom Directives
131+
132+
Globally registered custom directives just work as normal. Local custom directives don't need to be explicitly registered with `<script setup>`, but they must follow the naming scheme `vNameOfDirective`:
133+
134+
```vue
135+
<script setup>
136+
const vMyDirective = {
137+
beforeMount: (el) => {
138+
// do something with the element
139+
}
140+
}
141+
</script>
142+
<template>
143+
<h1 v-my-directive>This is a Heading</h1>
144+
</template>
145+
```
146+
147+
If you're importing a directive from elsewhere, it can be renamed to fit the required naming scheme:
148+
149+
```vue
150+
<script setup>
151+
import { myDirective as vMyDirective } from './MyDirective.js'
152+
</script>
153+
```
154+
130155
## defineProps() & defineEmits()
131156

132157
To declare options like `props` and `emits` with full type inference support, we can use the `defineProps` and `defineEmits` APIs, which are automatically available inside `<script setup>`:

src/examples/src/cells/App/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<tbody>
99
<tr v-for="i in cells[0].length">
1010
<th>{{ i - 1 }}</th>
11-
<td v-for="c, j in cols">
11+
<td v-for="(c, j) in cols">
1212
<Cell :r="i - 1" :c="j"></Cell>
1313
</td>
1414
</tr>

src/guide/best-practices/accessibility.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,27 @@ Avoid using placeholders as they can confuse many users.
277277

278278
One of the issues with placeholders is that they don't meet the [color contrast criteria](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html) by default; fixing the color contrast makes the placeholder look like pre-populated data in the input fields. Looking at the following example, you can see that the Last Name placeholder which meets the color contrast criteria looks like pre-populated data:
279279

280+
```vue-html
281+
<form
282+
class="demo"
283+
action="/dataCollectionLocation"
284+
method="post"
285+
autocomplete="on"
286+
>
287+
<div v-for="item in formItems" :key="item.id" class="form-item">
288+
<label :for="item.id">{{ item.label }}: </label>
289+
<input
290+
type="text"
291+
:id="item.id"
292+
:name="item.id"
293+
v-model="item.value"
294+
:placeholder="item.placeholder"
295+
/>
296+
</div>
297+
<button type="submit">Submit</button>
298+
</form>
299+
```
300+
280301
<!-- <common-codepen-snippet title="Form Placeholder" slug="ExZvvMw" :height="265" tab="js,result" theme="light" :preview="false" :editable="false" /> -->
281302

282303
It is best to provide all the information the user needs to fill out forms outside any inputs.

src/guide/components/images/scoped-slots.svg

Lines changed: 29 additions & 0 deletions
Loading

src/guide/components/slots.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ Receiving the slot props is a bit different when using a single default slot vs.
344344
</MyComponent>
345345
```
346346

347+
![scoped slots diagram](./images/scoped-slots.svg)
348+
349+
<!-- https://www.figma.com/file/QRneoj8eIdL1kw3WQaaEyc/scoped-slot -->
350+
347351
<div class="composition-api">
348352

349353
[Try it in the Playground](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbmltcG9ydCBNeUNvbXBvbmVudCBmcm9tICcuL015Q29tcG9uZW50LnZ1ZSdcbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG5cdDxNeUNvbXBvbmVudCB2LXNsb3Q9XCJzbG90UHJvcHNcIj5cbiAgXHR7eyBzbG90UHJvcHMudGV4dCB9fSB7eyBzbG90UHJvcHMuY291bnQgfX1cbiAgPC9NeUNvbXBvbmVudD5cbjwvdGVtcGxhdGU+IiwiaW1wb3J0LW1hcC5qc29uIjoie1xuICBcImltcG9ydHNcIjoge1xuICAgIFwidnVlXCI6IFwiaHR0cHM6Ly9zZmMudnVlanMub3JnL3Z1ZS5ydW50aW1lLmVzbS1icm93c2VyLmpzXCJcbiAgfVxufSIsIk15Q29tcG9uZW50LnZ1ZSI6IjxzY3JpcHQgc2V0dXA+XG5jb25zdCBncmVldGluZ01lc3NhZ2UgPSAnaGVsbG8nXG48L3NjcmlwdD5cblxuPHRlbXBsYXRlPlxuICA8ZGl2PlxuICBcdDxzbG90IDp0ZXh0PVwiZ3JlZXRpbmdNZXNzYWdlXCIgOmNvdW50PVwiMVwiPjwvc2xvdD5cblx0PC9kaXY+XG48L3RlbXBsYXRlPiJ9)
@@ -403,7 +407,7 @@ Named scoped slots work similarly - slot props are accessible as the value of th
403407
</template>
404408
405409
<template #footer="footerProps">
406-
{{ headerProps }}
410+
{{ footerProps }}
407411
</template>
408412
</MyComponent>
409413
```

0 commit comments

Comments
 (0)