Skip to content

Commit 447843f

Browse files
committed
更新 中英文对照方式。。。
1 parent 1a79026 commit 447843f

File tree

13 files changed

+2158
-579
lines changed

13 files changed

+2158
-579
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,27 @@ $ hexo server
1414

1515
Start a dev server at `localhost:4000`
1616

17-
## merge
17+
## merge
1818

1919
- 翻译完 pull request 到 2.0-cn 分支 合并
2020

21-
## 发布
21+
## 发布
2222

23-
> 预先添加git ssh
23+
> 预先添加git ssh
2424
2525
```
2626
hexo g
2727
hexo d
2828
```
2929

30-
## 当前说明(2016.08.14
30+
## 当前说明(2016.08.16
3131

3232
* 翻译到基础篇 /src/guide/components.md 组件 文档 http://vuefe.cn/guide/components.html
33-
* 中英文对照方式: 一段原文(英文) 接一段翻译 接 源码块,英文在前,保持原貌
33+
* 中英文对照方式: ***~~一段原文(英文) 接一段翻译 接 源码块,英文在前,保持原貌~~*** 用中文翻译在一起,英文原文在后的方式进行,方便后面实现左右中英文对照
3434
* 代码中注释直接翻译成中文,不需要留下英文
3535
* 暂且存在目录中英文共存的重复问题,暂时不必修改,就保留中英文目录
3636
* 请尽量对照 vuejs 官方 1.0 中文文档进行翻译,也可以即时看出vue1和vue2直接的区别
3737
* 导航上 添加了 更新 模块,用于链接到github的 release信息,后面希望单独把changelog放到 /changelog中跟进翻译每次的版本更新内容
3838
* (畅想:加入热点标记功能 - 点击热点新建github 对应 issue ,话题链接 / 增强文档交互即时纠错)
3939
* (畅想: 首页加入弹幕交互功能)
4040
* (畅想: 添加hacknews-vue2案例解析 以及更多自定义案例解析)
41-

src/guide/class-and-style.md

Lines changed: 164 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,192 @@ type: guide
44
order: 6
55
---
66

7-
A common need for data binding is manipulating an element's class list and its inline styles. Since they are both attributes, we can use `v-bind` to handle them: we just need to calculate a final string with our expressions. However, meddling with string concatenation is annoying and error-prone. For this reason, Vue provides special enhancements when `v-bind` is used with `class` and `style`. In addition to strings, the expressions can also evaluate to objects or arrays.
8-
97
数据绑定一个常见需求是操作元素的 class 列表和它的内联样式。因为它们都是 attribute,我们可以用 `v-bind` 处理它们:只需要计算出表达式最终的字符串。不过,字符串拼接麻烦又易错。因此,在 `v-bind` 用于 `class``style` 时,Vue.js 专门增强了它。表达式的结果类型除了字符串之外,还可以是对象或数组。
108

11-
## Binding HTML Classes
12-
13-
## 绑定 HTML Class
14-
15-
### Object Syntax
16-
17-
We can pass an object to `v-bind:class` to dynamically toggle classes:
9+
# 绑定 HTML Class
1810

19-
### 对象语法
11+
## 对象语法
2012

2113
我们可以传给 `v-bind:class` 一个对象,以动态地切换 class。
2214

2315
```html
2416
<div v-bind:class="{ active: isActive, 'text-danger': hasError }"></div>
2517
```
2618

27-
```js
19+
```javascript
2820
data: {
2921
isActive: true,
3022
hasEror: false
3123
}
3224
```
25+
3326
The `v-bind:class` directive can also co-exist with the plain `class` attribute:
3427

3528
`v-bind:class` 指令可以与普通的 `class` 特性共存:
3629

37-
``` html
30+
```html
3831
<div class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }"></div>
3932
```
4033

41-
This will render:
34+
渲染为:
35+
36+
```html
37+
<div class="static active"></div>
38+
```
39+
40+
`isActive``hasError` 变化时,class 列表将相应地更新。例如,如果 `hasError` 变为 `true`,class 列表将变为 `"static active text-danger"`
41+
42+
你也可以直接绑定数据里的一个对象:
43+
44+
```html
45+
<div v-bind:class="classObject"></div>
46+
```
47+
48+
```javascript
49+
data: {
50+
classObject: {
51+
active: true,
52+
'text-danger': false
53+
}
54+
}
55+
```
56+
57+
我们也可以在这里绑定一个返回对象的[计算属性](computed.html)。这是一个常用且强大的模式。
58+
59+
```html
60+
<div v-bind:class="classObject"></div>
61+
```
62+
63+
```javascript
64+
data: {
65+
isActive: true,
66+
error: null
67+
},
68+
computed: {
69+
classObject: function () {
70+
return {
71+
active: this.isActive && !this.error,
72+
'text-danger': this.error && this.error.type === 'fatal',
73+
}
74+
}
75+
}
76+
```
77+
78+
## 数组语法
79+
80+
我们可以把一个数组传给 `v-bind:class`,以应用一个 class 列表:
81+
82+
```html
83+
<div v-bind:class="[activeClass, errorClass]">
84+
```
85+
86+
```javascript
87+
data: {
88+
activeClass: 'active',
89+
errorClass: 'text-danger'
90+
}
91+
```
4292

4393
渲染为:
4494

95+
```html
96+
<div class="active text-danger"></div>
97+
```
98+
99+
如果你也想根据条件切换列表中的 class,可以用三元表达式:
100+
101+
```html
102+
<div v-bind:class="[isActive ? activeClass : '', errorClass]">
103+
```
104+
105+
此例始终添加 `errorClass`,但是只有在 `isActive``true` 时添加 `activeClass`
106+
107+
不过,当有多个条件 class 时这样写有些繁琐。这就是为什么可以在数组语法中使用对象语法:
108+
109+
```html
110+
<div v-bind:class="[{ active: isActive }, errorClass]">
111+
```
112+
113+
# 绑定内联样式
114+
115+
## 对象语法
116+
117+
`v-bind:style` 的对象语法十分直观----看着非常像 CSS,其实它是一个 JavaScript 对象。CSS 属性名可以用驼峰式(camelCase)或短横分隔命名(kebab-case):
118+
119+
```html
120+
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
121+
```
122+
123+
```javascript
124+
data: {
125+
activeColor: 'red',
126+
fontSize: 30
127+
}
128+
```
129+
130+
直接绑定到一个样式对象通常更好,让模板更清晰:
131+
132+
```html
133+
<div v-bind:style="styleObject"></div>
134+
```
135+
136+
```javascript
137+
data: {
138+
styleObject: {
139+
color: 'red',
140+
fontSize: '13px'
141+
}
142+
}
143+
```
144+
145+
同样的,对象语法常常结合返回对象的计算属性使用。
146+
147+
## 数组语法
148+
149+
`v-bind:style` 的数组语法可以将多个样式对象应用到一个元素上:
150+
151+
```html
152+
<div v-bind:style="[baseStyles, overridingStyles]">
153+
```
154+
155+
## 自动添加前缀
156+
157+
`v-bind:style` 使用需要厂商前缀的 CSS 属性时,如 `transform`,Vue.js 会自动侦测并添加相应的前缀。
158+
159+
--------------------------------------------------------------------------------
160+
161+
> 原文: http://rc.vuejs.org/guide/class-and-style.html
162+
163+
***
164+
165+
# Class and Style Bindings
166+
167+
A common need for data binding is manipulating an element's class list and its inline styles. Since they are both attributes, we can use `v-bind` to handle them: we just need to calculate a final string with our expressions. However, meddling with string concatenation is annoying and error-prone. For this reason, Vue provides special enhancements when `v-bind` is used with `class` and `style`. In addition to strings, the expressions can also evaluate to objects or arrays.
168+
169+
## Binding HTML Classes
170+
171+
### Object Syntax
172+
173+
We can pass an object to `v-bind:class` to dynamically toggle classes:
174+
175+
``` html
176+
<div v-bind:class="{ active: isActive, 'text-danger': hasError }"></div>
177+
```
178+
``` js
179+
data: {
180+
isActive: true,
181+
hasEror: false
182+
}
183+
```
184+
185+
The `v-bind:class` directive can also co-exist with the plain `class` attribute:
186+
187+
``` html
188+
<div class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }"></div>
189+
```
190+
191+
This will render:
192+
45193
``` html
46194
<div class="static active"></div>
47195
```
@@ -50,10 +198,6 @@ When `isActive` or `hasError` changes, the class list will be updated accordingl
50198

51199
You can also directly bind to an object:
52200

53-
`isActive``hasError` 变化时,class 列表将相应地更新。例如,如果 `hasError` 变为 `true`,class 列表将变为 `"static active text-danger"`
54-
55-
你也可以直接绑定数据里的一个对象:
56-
57201
``` html
58202
<div v-bind:class="classObject"></div>
59203
```
@@ -68,13 +212,10 @@ data: {
68212

69213
This will render the same result. We can also bind to a [computed property](computed.html) that returns an object. This is a common and powerful pattern:
70214

71-
我们也可以在这里绑定一个返回对象的[计算属性](computed.html)。这是一个常用且强大的模式。
72-
73-
```html
215+
``` html
74216
<div v-bind:class="classObject"></div>
75217
```
76-
77-
```js
218+
``` js
78219
data: {
79220
isActive: true,
80221
error: null
@@ -93,31 +234,24 @@ computed: {
93234

94235
We can pass an array to `v-bind:class` to apply a list of classes:
95236

96-
### 数组语法
97-
98-
我们可以把一个数组传给 `v-bind:class`,以应用一个 class 列表:
99-
100237
``` html
101238
<div v-bind:class="[activeClass, errorClass]">
102239
```
103-
104240
``` js
105241
data: {
106242
activeClass: 'active',
107243
errorClass: 'text-danger'
108244
}
109245
```
110246

111-
渲染为:
247+
Which will render:
112248

113249
``` html
114250
<div class="active text-danger"></div>
115251
```
116252

117253
If you would like to also toggle a class in the list conditionally, you can do it with a ternary expression:
118254

119-
如果你也想根据条件切换列表中的 class,可以用三元表达式:
120-
121255
``` html
122256
<div v-bind:class="[isActive ? activeClass : '', errorClass]">
123257
```
@@ -126,10 +260,6 @@ This will always apply `errorClass`, but will only apply `activeClass` when `isA
126260

127261
However, this can be a bit verbose if you have multiple conditional classes. That's why it's also possible to use the object syntax inside array syntax:
128262

129-
此例始终添加 `errorClass`,但是只有在 `isActive``true` 时添加 `activeClass`
130-
131-
不过,当有多个条件 class 时这样写有些繁琐。这就是为什么可以在数组语法中使用对象语法:
132-
133263
``` html
134264
<div v-bind:class="[{ active: isActive }, errorClass]">
135265
```
@@ -140,12 +270,6 @@ However, this can be a bit verbose if you have multiple conditional classes. Tha
140270

141271
The object syntax for `v-bind:style` is pretty straightforward - it looks almost like CSS, except it's a JavaScript object. You can use either camelCase or kebab-case for the CSS property names:
142272

143-
## 绑定内联样式
144-
145-
### 对象语法
146-
147-
`v-bind:style` 的对象语法十分直观——看着非常像 CSS,其实它是一个 JavaScript 对象。CSS 属性名可以用驼峰式(camelCase)或短横分隔命名(kebab-case):
148-
149273
``` html
150274
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
151275
```
@@ -158,8 +282,6 @@ data: {
158282

159283
It is often a good idea to bind to a style object directly so that the template is cleaner:
160284

161-
直接绑定到一个样式对象通常更好,让模板更清晰:
162-
163285
``` html
164286
<div v-bind:style="styleObject"></div>
165287
```
@@ -178,20 +300,10 @@ Again, the object syntax is often used in conjunction with computed properties t
178300

179301
The array syntax for `v-bind:style` allows you to apply multiple style objects to the same element:
180302

181-
同样的,对象语法常常结合返回对象的计算属性使用。
182-
183-
### 数组语法
184-
185-
`v-bind:style` 的数组语法可以将多个样式对象应用到一个元素上:
186-
187303
``` html
188304
<div v-bind:style="[baseStyles, overridingStyles]">
189305
```
190306

191307
### Auto-prefixing
192308

193309
When you use a CSS property that requires vendor prefixes in `v-bind:style`, for example `transform`, Vue will automatically detect and add appropriate prefixes to the applied styles.
194-
195-
### 自动添加前缀
196-
197-
`v-bind:style` 使用需要厂商前缀的 CSS 属性时,如 `transform`,Vue.js 会自动侦测并添加相应的前缀。

0 commit comments

Comments
 (0)