You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/macros/define-model.md
+32-6Lines changed: 32 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,42 @@ Declaring and mutate `v-model` props as the same as normal variable using the `d
5
5
| Features| Supported|
6
6
| :----------------:| :----------------:|
7
7
| Vue 3|:white_check_mark:|
8
-
| Vue 2|:x:|
8
+
| Vue 2|:white_check_mark:|
9
9
| TypeScript / Volar|:white_check_mark:|
10
10
11
+
##Usage
12
+
13
+
```vue
14
+
<script setup lang="ts">
15
+
const { modelValue, count } = defineModel<{
16
+
modelValue: string
17
+
count: number
18
+
}>()
19
+
20
+
console.log(modelValue.value)
21
+
modelValue.value = 'newValue'
22
+
</script>
23
+
```
24
+
25
+
::: warning ❌ Object declaring is not supported.
26
+
27
+
```vue
28
+
<script setup lang="ts">
29
+
const { modelValue } = defineModel({
30
+
modelValue: String,
31
+
})
32
+
</script>
33
+
```
34
+
35
+
:::
36
+
37
+
##With Reactivity Transform
38
+
11
39
::: warning
12
40
13
41
[Reactivity Transform](https://vuejs.org/guide/extras/reactivity-transform.html) is required. You should enable it first. Otherwise, it will lose the reactivity connection.
14
42
15
-
Unfortunately Reactivity Transform is not implemented in Vue 2, so thismacros doesn't support Vue 2 now.
43
+
Unfortunately Reactivity Transform is not implemented in Vue 2, so thismacro doesn't support Vue 2 now.
16
44
17
45
:::
18
46
@@ -22,11 +50,9 @@ Assignment expression is only supported in `<script setup>` block. In other word