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: src/api/sfc-script-setup.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -298,16 +298,20 @@ function inc() {
298
298
:::warning
299
299
If you have a `default` value for `defineModel` prop and you don't provide any value for this prop from the parent component, it can cause a de-synchronization between parent and child components. In the example below, the parent's `myRef` is undefined, but the child's `model` is 1:
Copy file name to clipboardExpand all lines: src/guide/built-ins/transition.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -469,8 +469,7 @@ Here's a demo using the [GSAP library](https://gsap.com/) to perform the animati
469
469
470
470
Transitions can be reused through Vue's component system. To create a reusable transition, we can create a component that wraps the `<Transition>` component and passes down the slot content:
In order to make injections reactively linked to the provider, we need to provide a computed property using the [computed()](/api/reactivity-core#computed) function:
299
299
300
-
```js{10}
300
+
```js{12}
301
301
import { computed } from 'vue'
302
302
303
303
export default {
@@ -327,8 +327,7 @@ So far, we have been using string injection keys in the examples. If you are wor
327
327
328
328
It's recommended to export the Symbols in a dedicated file:
If you have a `default` value for `defineModel` prop and you don't provide any value for this prop from the parent component, it can cause a de-synchronization between parent and child components. In the example below, the parent's `myRef` is undefined, but the child's `model` is 1:
105
101
106
-
**Child component:**
107
-
108
-
```js
102
+
```vue [Child.vue]
103
+
<script setup>
109
104
const model = defineModel({ default: 1 })
105
+
</script>
110
106
```
111
107
112
-
**Parent component:**
113
-
114
-
```js
108
+
```vue [Parent.vue]
109
+
<script setup>
115
110
const myRef = ref()
116
-
```
111
+
</script>
117
112
118
-
```html
119
-
<Childv-model="myRef"></Child>
113
+
<template>
114
+
<Child v-model="myRef"></Child>
115
+
</template>
120
116
```
121
117
122
118
:::
@@ -156,8 +152,7 @@ For this to actually work though, the `<CustomInput>` component must do two thin
156
152
157
153
Here's that in action:
158
154
159
-
```vue
160
-
<!-- CustomInput.vue -->
155
+
```vue [CustomInput.vue]
161
156
<script>
162
157
export default {
163
158
props: ['modelValue'],
@@ -183,8 +178,7 @@ Now `v-model` should work perfectly with this component:
183
178
184
179
Another way of implementing `v-model` within this component is to use a writable `computed` property with both a getter and a setter. The `get` method should return the `modelValue` property and the `set` method should emit the corresponding event:
185
180
186
-
```vue
187
-
<!-- CustomInput.vue -->
181
+
```vue [CustomInput.vue]
188
182
<script>
189
183
export default {
190
184
props: ['modelValue'],
@@ -221,8 +215,7 @@ export default {
221
215
222
216
In the child component, we can support the corresponding argument by passing a string to `defineModel()` as its first argument:
In this case, instead of the default `modelValue` prop and `update:modelValue` event, the child component should expect a `title` prop and emit an `update:title` event to update the parent value:
To conditionally adjust how the value should be read / written based on modifiers, we can pass `get` and `set` options to `defineModel()`. These two options receive the value on get / set of the model ref and should return a transformed value. This is how we can use the `set` option to implement the `capitalize` modifier:
Copy file name to clipboardExpand all lines: src/guide/essentials/component-basics.md
+9-14Lines changed: 9 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -188,8 +188,7 @@ Props are custom attributes you can register on a component. To pass a title to
188
188
189
189
<divclass="options-api">
190
190
191
-
```vue
192
-
<!-- BlogPost.vue -->
191
+
```vue [BlogPost.vue]
193
192
<script>
194
193
export default {
195
194
props: ['title']
@@ -206,8 +205,7 @@ When a value is passed to a prop attribute, it becomes a property on that compon
206
205
</div>
207
206
<divclass="composition-api">
208
207
209
-
```vue
210
-
<!-- BlogPost.vue -->
208
+
```vue [BlogPost.vue]
211
209
<script setup>
212
210
defineProps(['title'])
213
211
</script>
@@ -352,8 +350,8 @@ Which can be used in the template to control the font size of all blog posts:
352
350
353
351
Now let's add a button to the `<BlogPost>` component's template:
354
352
355
-
```vue{5}
356
-
<!-- BlogPost.vue, omitting <script> -->
353
+
```vue{5} [BlogPost.vue]
354
+
<!-- omitting <script> -->
357
355
<template>
358
356
<div class="blog-post">
359
357
<h4>{{ title }}</h4>
@@ -373,8 +371,8 @@ The button doesn't do anything yet - we want clicking the button to communicate
373
371
374
372
Then the child component can emit an event on itself by calling the built-in [**`$emit`** method](/api/component-instance#emit), passing the name of the event:
375
373
376
-
```vue{5}
377
-
<!-- BlogPost.vue, omitting <script> -->
374
+
```vue{5} [BlogPost.vue]
375
+
<!-- omitting <script> -->
378
376
<template>
379
377
<div class="blog-post">
380
378
<h4>{{ title }}</h4>
@@ -400,8 +398,7 @@ We can optionally declare emitted events using the <span class="options-api">[`e
400
398
401
399
<divclass="options-api">
402
400
403
-
```vue{5}
404
-
<!-- BlogPost.vue -->
401
+
```vue{4} [BlogPost.vue]
405
402
<script>
406
403
export default {
407
404
props: ['title'],
@@ -413,8 +410,7 @@ export default {
413
410
</div>
414
411
<divclass="composition-api">
415
412
416
-
```vue{4}
417
-
<!-- BlogPost.vue -->
413
+
```vue{3} [BlogPost.vue]
418
414
<script setup>
419
415
defineProps(['title'])
420
416
defineEmits(['enlarge-text'])
@@ -472,8 +468,7 @@ Something bad happened.
472
468
473
469
This can be achieved using Vue's custom `<slot>` element:
474
470
475
-
```vue{5}
476
-
<!-- AlertBox.vue -->
471
+
```vue{4} [AlertBox.vue]
477
472
<template>
478
473
<div class="alert-box">
479
474
<strong>This is an Error for Demo Purposes</strong>
Copy file name to clipboardExpand all lines: src/guide/extras/web-components.md
+7-15Lines changed: 7 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,8 +43,7 @@ export default {
43
43
44
44
#### Example Vue CLI Config {#example-vue-cli-config}
45
45
46
-
```js
47
-
// vue.config.js
46
+
```js [vue.config.js]
48
47
module.exports= {
49
48
chainWebpack: (config) => {
50
49
config.module
@@ -218,8 +217,7 @@ If the custom elements will be used in an application that is also using Vue, yo
218
217
219
218
It is recommended to export the individual element constructors to give your users the flexibility to import them on-demand and register them with desired tag names. You can also export a convenience function to automatically register all elements. Here's an example entry point of a Vue custom element library:
220
219
221
-
```js
222
-
// elements.js
220
+
```js [elements.js]
223
221
224
222
import { defineCustomElement } from'vue'
225
223
importFoofrom'./MyFoo.ce.vue'
@@ -311,9 +309,7 @@ This approach is one possible way to do it, but it may vary depending on the fra
311
309
312
310
Suppose we have a custom element with some JS properties and events defined, and it is shipped in a library called `some-lib`:
313
311
314
-
```ts
315
-
// file: some-lib/src/SomeElement.ts
316
-
312
+
```ts [some-lib/src/SomeElement.ts]
317
313
// Define a class with typed JS properties.
318
314
exportclassSomeElementextendsHTMLElement {
319
315
foo:number=123
@@ -351,9 +347,7 @@ The implementation details have been omitted, but the important part is that we
351
347
352
348
Let's create a type helper for easily registering custom element type definitions in Vue:
353
349
354
-
```ts
355
-
// file: some-lib/src/DefineCustomElement.ts
356
-
350
+
```ts [some-lib/src/DefineCustomElement.ts]
357
351
// We can re-use this type helper per each element we need to define.
358
352
typeDefineCustomElement<
359
353
ElementTypeextendsHTMLElement,
@@ -394,9 +388,7 @@ We marked `$props` and `$emit` as deprecated so that when we get a `ref` to a cu
394
388
395
389
Using the type helper we can now select the JS properties that should be exposed for type checking in Vue templates:
396
390
397
-
```ts
398
-
// file: some-lib/src/SomeElement.vue.ts
399
-
391
+
```ts [some-lib/src/SomeElement.vue.ts]
400
392
import {
401
393
SomeElement,
402
394
SomeElementAttributes,
@@ -419,7 +411,7 @@ declare module 'vue' {
419
411
420
412
Suppose that `some-lib` builds its source TypeScript files into a `dist/` folder. A user of `some-lib` can then import `SomeElement` and use it in a Vue SFC like so:
421
413
422
-
```vue
414
+
```vue [SomeElementImpl.vue]
423
415
<script setup lang="ts">
424
416
// This will create and register the element with the browser.
425
417
import 'some-lib/dist/SomeElement.js'
@@ -465,7 +457,7 @@ onMounted(() => {
465
457
466
458
If an element does not have type definitions, the types of the properties and events can be defined in a more manual fashion:
467
459
468
-
```vue
460
+
```vue [SomeElementImpl.vue]
469
461
<script setup lang="ts">
470
462
// Suppose that `some-lib` is plain JS without type definitions, and TypeScript
0 commit comments