Skip to content

Commit 20eb82a

Browse files
author
ntepluhina
committed
fix: fixed class and style
1 parent 6d5261b commit 20eb82a

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

src/guide/class-and-style.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ You can have multiple classes toggled by having more fields in the object. In ad
2828
And the following data:
2929

3030
```js
31-
data: {
32-
isActive: true,
33-
hasError: false
31+
data() {
32+
return {
33+
isActive: true,
34+
hasError: false
35+
}
3436
}
3537
```
3638

@@ -49,10 +51,12 @@ The bound object doesn't have to be inline:
4951
```
5052

5153
```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+
}
5660
}
5761
}
5862
```
@@ -64,9 +68,11 @@ This will render the same result. We can also bind to a [computed property](comp
6468
```
6569

6670
```js
67-
data: {
68-
isActive: true,
69-
error: null
71+
data() {
72+
return {
73+
isActive: true,
74+
error: null
75+
}
7076
},
7177
computed: {
7278
classObject() {
@@ -87,9 +93,11 @@ We can pass an array to `v-bind:class` to apply a list of classes:
8793
```
8894

8995
```js
90-
data: {
91-
activeClass: 'active',
92-
errorClass: 'text-danger'
96+
data() {
97+
return {
98+
activeClass: 'active',
99+
errorClass: 'text-danger'
100+
}
93101
}
94102
```
95103

@@ -122,9 +130,11 @@ When you use the `class` attribute on a custom component, those classes will be
122130
For example, if you declare this component:
123131

124132
```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+
});
128138
```
129139

130140
Then add some classes when using it:
@@ -135,17 +145,6 @@ Then add some classes when using it:
135145
</div>
136146
```
137147

138-
```js
139-
Vue.createApp().mount(
140-
{
141-
components: {
142-
'my-component': MyComponent
143-
}
144-
},
145-
'#app'
146-
)
147-
```
148-
149148
The rendered HTML will be:
150149

151150
```html
@@ -177,9 +176,11 @@ The object syntax for `v-bind:style` is pretty straightforward - it looks almost
177176
```
178177

179178
```js
180-
data: {
181-
activeColor: 'red',
182-
fontSize: 30
179+
data() {
180+
return {
181+
activeColor: 'red',
182+
fontSize: 30
183+
}
183184
}
184185
```
185186

@@ -190,10 +191,12 @@ It is often a good idea to bind to a style object directly so that the template
190191
```
191192

192193
```js
193-
data: {
194-
styleObject: {
195-
color: 'red',
196-
fontSize: '13px'
194+
data() {
195+
return {
196+
styleObject: {
197+
color: 'red',
198+
fontSize: '13px'
199+
}
197200
}
198201
}
199202
```

0 commit comments

Comments
 (0)