|
2 | 2 |
|
3 | 3 | For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes.
|
4 | 4 |
|
5 |
| -Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. |
| 5 | +How to make it dynamic? We need to create our first _reactive_ property `colorsNumber` |
6 | 6 |
|
7 |
| -For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. |
8 |
| - |
9 |
| -Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. |
| 7 | +<div class="options-api"> |
10 | 8 |
|
11 |
| -For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. |
| 9 | +```js |
| 10 | +data() { |
| 11 | + return { |
| 12 | + colorsNumber: 3 |
| 13 | + } |
| 14 | +} |
| 15 | +``` |
12 | 16 |
|
13 |
| -Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. |
| 17 | +</div> |
14 | 18 |
|
15 |
| -For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. |
| 19 | +<div class="composition-api"> |
16 | 20 |
|
17 |
| -Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. |
| 21 | +```js |
| 22 | +import { ref } from 'vue' |
| 23 | +const colorsNumber = ref(3) |
| 24 | +``` |
18 | 25 |
|
19 |
| -For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. |
| 26 | +</div> |
20 | 27 |
|
21 |
| -Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. |
| 28 | +Now, we can use it in our template instead of a static number: |
22 | 29 |
|
23 |
| -For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. |
| 30 | +```html |
| 31 | +<h2>Number of colors: {{ colorsNumber }}</h2> |
| 32 | +``` |
24 | 33 |
|
25 |
| -Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. |
| 34 | +Try to change the `colorsNumber` and check how it immediately updates the rendered HTML. |
0 commit comments