Skip to content

Commit 8f553b6

Browse files
KimYangOfCatwxsms
andauthored
docs: review class-and-style.md (#106)
* docs: review class-and-style.md * Apply suggestions from code review Co-authored-by: wxsm <wxsms@foxmail.com> Co-authored-by: wxsm <wxsms@foxmail.com>
1 parent 140a013 commit 8f553b6

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/guide/essentials/class-and-style.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 类与样式绑定 {#class-and-style-bindings}
22

3-
数据绑定的一个常见需求场景是操纵元素的 CSS 类列表和内联样式。因为它们都是 attribute,我们可以使用 `v-bind` 来做这件事:我们只需要通过表达式计算出一个字符串作为最终结果即可。然而频繁操作字符串连接很闹心,也很容易出错的。因此 Vue `class``style``v-bind` 使用提供了特殊的功能增强。除了字符串外,表达式的结果还可以是对象或数组。
3+
数据绑定的一个常见需求场景是操纵元素的 CSS 类列表和内联样式。因为它们都是 attribute,我们可以使用 `v-bind` 来做这件事:我们只需要通过表达式计算出一个字符串作为最终结果即可。然而频繁地连接字符串让人很闹心,也很容易出错。因此Vue 专门为 `class``style``v-bind` 用法提供了特殊的功能增强。除了字符串外,表达式的结果还可以是对象或数组。
44

55
## 绑定 HTML 类 {#binding-html-classes}
66

@@ -55,7 +55,7 @@ data() {
5555
></div>
5656
```
5757

58-
这会渲染出
58+
它将会被渲染成
5959

6060
```vue-html
6161
<div class="static active"></div>
@@ -95,7 +95,7 @@ data() {
9595
<div :class="classObject"></div>
9696
```
9797

98-
这会渲染出相同的结果。我们也可以绑定一个返回对象的[计算属性](./computed)这是一个通用且好用的实践
98+
这也会渲染出相同的结果。我们也可以绑定一个返回对象的[计算属性](./computed)这才是一个通用且好用的实践
9999

100100
<div class="composition-api">
101101

@@ -188,9 +188,9 @@ data() {
188188

189189
### 和组件配合 {#with-components}
190190

191-
> 这一节假设你已经有 [Vue 组件](/guide/essentials/component-basics)的知识基础。如果没有,你也可以暂时跳过之后再回来
191+
> 本节假设你已经有 [Vue 组件](/guide/essentials/component-basics)的知识基础。如果没有,你也可以暂时跳过,以后再阅读
192192
193-
当你在一个根组件为单个元素的自定义组件上使用 `class` attribute 时,类列表会被添加到该元素上。已经存在在该元素上的类列表不会被覆盖
193+
对于只有一个根元素的组件,当你使用了 `class` attribute 时,这些类会被添加到根元素上,并与该元素上已有的类合并
194194

195195
举个例子,如果你声明了一个组件名叫 `my-component`,模板如下:
196196

@@ -212,7 +212,7 @@ data() {
212212
<p class="foo bar baz boo">Hi</p>
213213
```
214214

215-
类的绑定也是同样
215+
类的绑定也是同样的
216216

217217
```vue-html
218218
<my-component :class="{ active: isActive }"></my-component>
@@ -224,7 +224,7 @@ data() {
224224
<p class="foo bar active">Hi</p>
225225
```
226226

227-
如果你的组件有多个根元素,你将需要定义哪个元素接收这个类。你可以使用组件的 `$attrs` 这个属性
227+
如果你的组件有多个根元素,你将需要指定哪个根元素来接收这个类。你可以通过组件的 `$attrs` property 来实现指定
228228

229229
```vue-html
230230
<!-- my-component template using $attrs -->
@@ -236,14 +236,14 @@ data() {
236236
<my-component class="baz"></my-component>
237237
```
238238

239-
Will render
239+
这将被渲染为
240240

241241
```html
242242
<p class="baz">Hi!</p>
243243
<span>This is a child component</span>
244244
```
245245

246-
你可以在[透传 Attribute](/guide/components/attrs.html) 一章中学习到更多组件的 attribute 细节
246+
你可以在[透传 Attribute](/guide/components/attrs.html) 一章中学习到更多组件的 attribute 继承的细节
247247

248248
## 绑定内联样式 {#binding-inline-styles}
249249

@@ -273,8 +273,6 @@ data() {
273273

274274
</div>
275275

276-
在模板中直接用一个对象变量绑定给 style 会看起来更简洁:
277-
278276
```vue-html
279277
<div :style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
280278
```
@@ -285,7 +283,7 @@ data() {
285283
<div :style="{ 'font-size': fontSize + 'px' }"></div>
286284
```
287285

288-
在模板中对 style 绑定对象通常更加简洁
286+
直接绑定一个样式对象通常是一个好主意,这样可以使模板更加简洁
289287

290288
<div class="composition-api">
291289

@@ -317,7 +315,7 @@ data() {
317315
<div :style="styleObject"></div>
318316
```
319317

320-
同样的,如果样式对象需要更复杂的逻辑,也可以使用返回计算属性
318+
同样的,如果样式对象需要更复杂的逻辑,也可以使用返回样式对象的计算属性
321319

322320
### 绑定数组 {#binding-to-arrays-2}
323321

@@ -339,4 +337,4 @@ data() {
339337
<div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"></div>
340338
```
341339

342-
数组仅会渲染最后一个值,只要浏览器支持。在这个示例中,在支持不需要特别加前缀的浏览器中都会渲染为 `display: flex` 的弹性盒子。
340+
数组仅会渲染游览器支持的最后一个值。在这个示例中,在支持不需要特别加前缀的浏览器中都会渲染为 `display: flex` 的弹性盒子。

0 commit comments

Comments
 (0)