@@ -28,9 +28,11 @@ You can have multiple classes toggled by having more fields in the object. In ad
28
28
And the following data:
29
29
30
30
``` js
31
- data: {
32
- isActive: true ,
33
- hasError: false
31
+ data () {
32
+ return {
33
+ isActive: true ,
34
+ hasError: false
35
+ }
34
36
}
35
37
```
36
38
@@ -49,10 +51,12 @@ The bound object doesn't have to be inline:
49
51
```
50
52
51
53
``` js
52
- data: {
53
- classObject: {
54
- active: true ,
55
- ' text-danger' : false
54
+ data () {
55
+ return {
56
+ classObject: {
57
+ active: true ,
58
+ ' text-danger' : false
59
+ }
56
60
}
57
61
}
58
62
```
@@ -64,9 +68,11 @@ This will render the same result. We can also bind to a [computed property](comp
64
68
```
65
69
66
70
``` js
67
- data: {
68
- isActive: true ,
69
- error: null
71
+ data () {
72
+ return {
73
+ isActive: true ,
74
+ error: null
75
+ }
70
76
},
71
77
computed: {
72
78
classObject () {
@@ -87,9 +93,11 @@ We can pass an array to `v-bind:class` to apply a list of classes:
87
93
```
88
94
89
95
``` js
90
- data: {
91
- activeClass: ' active' ,
92
- errorClass: ' text-danger'
96
+ data () {
97
+ return {
98
+ activeClass: ' active' ,
99
+ errorClass: ' text-danger'
100
+ }
93
101
}
94
102
```
95
103
@@ -122,9 +130,11 @@ When you use the `class` attribute on a custom component, those classes will be
122
130
For example, if you declare this component:
123
131
124
132
``` js
125
- const MyComponent = {
126
- template: ' <p class="foo bar">Hi!</p>'
127
- }
133
+ const app = Vue .createApp ();
134
+
135
+ app .component (" my-component" , {
136
+ template: ` <p class="foo bar">Hi!</p>`
137
+ });
128
138
```
129
139
130
140
Then add some classes when using it:
@@ -135,17 +145,6 @@ Then add some classes when using it:
135
145
</div >
136
146
```
137
147
138
- ``` js
139
- Vue .createApp ().mount (
140
- {
141
- components: {
142
- ' my-component' : MyComponent
143
- }
144
- },
145
- ' #app'
146
- )
147
- ```
148
-
149
148
The rendered HTML will be:
150
149
151
150
``` html
@@ -177,9 +176,11 @@ The object syntax for `v-bind:style` is pretty straightforward - it looks almost
177
176
```
178
177
179
178
``` js
180
- data: {
181
- activeColor: ' red' ,
182
- fontSize: 30
179
+ data () {
180
+ return {
181
+ activeColor: ' red' ,
182
+ fontSize: 30
183
+ }
183
184
}
184
185
```
185
186
@@ -190,10 +191,12 @@ It is often a good idea to bind to a style object directly so that the template
190
191
```
191
192
192
193
``` js
193
- data: {
194
- styleObject: {
195
- color: ' red' ,
196
- fontSize: ' 13px'
194
+ data () {
195
+ return {
196
+ styleObject: {
197
+ color: ' red' ,
198
+ fontSize: ' 13px'
199
+ }
197
200
}
198
201
}
199
202
```
0 commit comments