-
Notifications
You must be signed in to change notification settings - Fork 4.9k
3.5 updates #2987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
3.5 updates #2987
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0481a1d
3.5: failSilently for onScopeDispose
yyx990803 db3ba8d
3.5: reactive props destructure
yyx990803 ef3eea4
3.5: watcher side effect cleanup + WatchHandle pause / resume
yyx990803 4fa98d4
3.5: watch deep support number
yyx990803 d0918cd
3.5: useId and app.config.idPrefix
yyx990803 c44739a
3.5: lazy hydration
yyx990803 caa99ca
3.5: data-allow-mismatch
yyx990803 43b0da6
3.5: add composition api helpers page
yyx990803 256b92a
useAttrs, useSlots, useModel
yyx990803 30e5a07
3.5: useTemplateRef()
yyx990803 5c0ee2b
app.config.throwUnhandledErrorInProduction
yyx990803 6860d60
remove version badages for previous minors
yyx990803 7c69e91
3.5: deferred teleport
yyx990803 1564445
3.5: custom elements
yyx990803 a06ac21
3.5: props destructure extras
yyx990803 824deb9
fix dead link
yyx990803 ab41e36
Update src/api/application.md
yyx990803 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Composition API: Helpers {#composition-api-helpers} | ||
|
||
## useAttrs() {#useattrs} | ||
|
||
Returns the `attrs` object from the [Setup Context](/api/composition-api-setup#setup-context), which includes the [fallthrough attributes](/guide/components/attrs#fallthrough-attributes) of the current component. This is intended to be used in `<script setup>` where the setup context object is not available. | ||
|
||
- **Type** | ||
|
||
```ts | ||
function useAttrs(): Record<string, unknown> | ||
``` | ||
|
||
## useSlots() {#useslots} | ||
|
||
Returns the `slots` object from the [Setup Context](/api/composition-api-setup#setup-context), which includes parent passed slots as callable functions that return Virtual DOM nodes. This is intended to be used in `<script setup>` where the setup context object is not available. | ||
|
||
If using TypeScript, [`defineSlots()`](/api/sfc-script-setup#defineslots) should be preferred instead. | ||
|
||
- **Type** | ||
|
||
```ts | ||
function useSlots(): Record<string, (...args: any[]) => VNode[]> | ||
``` | ||
|
||
## useModel() {#usemodel} | ||
|
||
This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setup#definemodel). If using `<script setup>`, `defineModel()` should be preferred instead. | ||
|
||
- Only available in 3.4+ | ||
|
||
- **Type** | ||
|
||
```ts | ||
function useModel( | ||
props: Record<string, any>, | ||
key: string, | ||
options?: DefineModelOptions | ||
) | ||
|
||
type DefineModelOptions<T = any> = { | ||
get?: (v: T) => any | ||
set?: (v: T) => any | ||
} | ||
``` | ||
|
||
- **Example** | ||
|
||
```js | ||
export default { | ||
props: ['count'], | ||
emits: ['update:count'], | ||
setup(props) { | ||
const msg = useModel(props, 'count') | ||
msg.value = 1 | ||
} | ||
} | ||
``` | ||
|
||
- **Details** | ||
|
||
`useModel()` can be used in non-SFC components, e.g. when using raw `setup()` function. It expects the `props` object as the first argument, and the model name as the second argument. The optional third argument can be used to declare custom getter and setter for the resulting model ref. Note that unlike `defineModel()`, you are responsible for declaring the props and emits yourself. | ||
|
||
## useTemplateRef() <sup class="vt-badge" data-text="3.5+" /> {#usetemplateref} | ||
|
||
Returns a shallow ref whose value will be synced with the template element or component with a matching ref attribute. | ||
|
||
- **Type** | ||
|
||
```ts | ||
function useTemplateRef<T>(key: string): Readonly<ShallowRef<T | null>> | ||
``` | ||
|
||
- **Example** | ||
|
||
```vue | ||
<script setup> | ||
import { useTemplateRef, onMounted } from 'vue' | ||
|
||
const inputRef = useTemplateRef('input') | ||
|
||
onMounted(() => { | ||
inputRef.value.focus() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<input ref="input" /> | ||
</template> | ||
``` | ||
|
||
- **See also** | ||
- [Guide - Template Refs](/guide/essentials/template-refs) | ||
- [Guide - Typing Template Refs](/guide/typescript/composition-api#typing-template-refs) <sup class="vt-badge ts" /> | ||
- [Guide - Typing Component Template Refs](/guide/typescript/composition-api#typing-component-template-refs) <sup class="vt-badge ts" /> | ||
|
||
## useId() <sup class="vt-badge" data-text="3.5+" /> {#useid} | ||
|
||
Used to generate unique-per-application IDs for accessibility attributes or form elements. | ||
|
||
- **Type** | ||
|
||
```ts | ||
function useId(): string | ||
``` | ||
|
||
- **Example** | ||
|
||
```vue | ||
<script setup> | ||
import { useId } from 'vue' | ||
|
||
const id = useId() | ||
</script> | ||
|
||
<template> | ||
<form> | ||
<label :for="id">Name:</label> | ||
<input :id="id" type="text" /> | ||
</form> | ||
</template> | ||
``` | ||
|
||
- **Details** | ||
|
||
IDs generated by `useId()` are unique-per-application. It can be used to generate IDs for form elements and accessibility attributes. Multiple calls in the same component will generate different IDs; multiple instances of the same component calling `useId()` will also have different IDs. | ||
|
||
IDs generated by `useId()` are also guaranteed to be stable across the server and client renders, so they can be used in SSR applications without leading to hydration mismatches. | ||
|
||
If you have more than one Vue application instance of the same page, you can avoid ID conflicts by giving each app an ID prefix via [`app.config.idPrefix`](/api/application#app-config-idprefix). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.