Skip to content

Commit fdde14b

Browse files
authored
Translated D1~D4 of style guide (#564)
* Translated all style guide. * typo
1 parent 03254a6 commit fdde14b

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/v2/style-guide/index.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -1489,22 +1489,22 @@ computed: {
14891489

14901490

14911491

1492-
## Priority D Rules: Use with Caution (Potentially Dangerous Patterns)
1492+
## 优先级 D 的规则:谨慎使用 (有潜在危险的模式)
14931493

14941494

14951495

1496-
### `v-if`/`v-if-else`/`v-else` without `key` <sup data-p="d">use with caution</sup>
1496+
### 没有在 `v-if`/`v-if-else`/`v-else` 中使用 `key` <sup data-p="d">谨慎使用</sup>
14971497

1498-
**It's usually best to use `key` with `v-if` + `v-else`, if they are the same element type (e.g. both `<div>` elements).**
1498+
**如果一组 `v-if` + `v-else` 的元素类型相同,最好使用 `key` (比如两个 `<div>` 元素)。**
14991499

1500-
By default, Vue updates the DOM as efficiently as possible. That means when switching between elements of the same type, it simply patches the existing element, rather than removing it and adding a new one in its place. This can have [unintended side effects](https://jsfiddle.net/chrisvfritz/bh8fLeds/) if these elements should not actually be considered the same.
1500+
默认情况下,Vue 会尽可能高效的更新 DOM。这意味着其在相同类型的元素之间切换时,会修补以存在的元素,而不是将旧的元素移除然后在同一位置添加一个新元素。如果本不相同的元素被识别为相同,则会出现[意料之外的副作用](https://jsfiddle.net/chrisvfritz/bh8fLeds/)
15011501

15021502
{% raw %}<div class="style-example example-bad">{% endraw %}
15031503
#### 反例
15041504

15051505
``` html
15061506
<div v-if="error">
1507-
Error: {{ error }}
1507+
错误:{{ error }}
15081508
</div>
15091509
<div v-else>
15101510
{{ results }}
@@ -1517,7 +1517,7 @@ By default, Vue updates the DOM as efficiently as possible. That means when swit
15171517

15181518
``` html
15191519
<div v-if="error" key="search-status">
1520-
Error: {{ error }}
1520+
错误:{{ error }}
15211521
</div>
15221522
<div v-else key="search-results">
15231523
{{ results }}
@@ -1526,7 +1526,7 @@ By default, Vue updates the DOM as efficiently as possible. That means when swit
15261526

15271527
``` html
15281528
<p v-if="error">
1529-
Error: {{ error }}
1529+
错误:{{ error }}
15301530
</p>
15311531
<div v-else>
15321532
{{ results }}
@@ -1536,11 +1536,11 @@ By default, Vue updates the DOM as efficiently as possible. That means when swit
15361536

15371537

15381538

1539-
### Element selectors with `scoped` <sup data-p="d">use with caution</sup>
1539+
### `scoped` 中的元素选择器 <sup data-p="d">谨慎使用</sup>
15401540

1541-
**Element selectors should be avoided with `scoped`.**
1541+
**元素选择器应该避免在 `scoped` 中出现。**
15421542

1543-
Prefer class selectors over element selectors in `scoped` styles, because large numbers of element selectors are slow.
1543+
`scoped` 样式中,类选择器比元素选择器更好,因为大量使用元素选择器是很慢的。
15441544

15451545
{% raw %}
15461546
<details>
@@ -1549,9 +1549,9 @@ Prefer class selectors over element selectors in `scoped` styles, because large
15491549
</summary>
15501550
{% endraw %}
15511551

1552-
To scope styles, Vue adds a unique attribute to component elements, such as `data-v-f3f3eg9`. Then selectors are modified so that only matching elements with this attribute are selected (e.g. `button[data-v-f3f3eg9]`).
1552+
为了给样式设置作用域,Vue 会为元素添加一个独一无二的特性,例如 `data-v-f3f3eg9`。然后修改选择器,使得在匹配选择器的元素中,只有带这个特性才会真正生效 (比如 `button[data-v-f3f3eg9]`)
15531553

1554-
The problem is that large numbers of [element-attribute selectors](http://stevesouders.com/efws/css-selectors/csscreate.php?n=1000&sel=a%5Bhref%5D&body=background%3A+%23CFD&ne=1000) (e.g. `button[data-v-f3f3eg9]`) will be considerably slower than [class-attribute selectors](http://stevesouders.com/efws/css-selectors/csscreate.php?n=1000&sel=.class%5Bhref%5D&body=background%3A+%23CFD&ne=1000) (e.g. `.btn-close[data-v-f3f3eg9]`), so class selectors should be preferred whenever possible.
1554+
问题在于大量的[元素和特性组合的选择器](http://stevesouders.com/efws/css-selectors/csscreate.php?n=1000&sel=a%5Bhref%5D&body=background%3A+%23CFD&ne=1000) (比如 `button[data-v-f3f3eg9]`) 会比[类和特性组合的选择器](http://stevesouders.com/efws/css-selectors/csscreate.php?n=1000&sel=.class%5Bhref%5D&body=background%3A+%23CFD&ne=1000) 慢,所以应该尽可能选用类选择器。
15551555

15561556
{% raw %}</details>{% endraw %}
15571557

@@ -1589,13 +1589,13 @@ button {
15891589

15901590

15911591

1592-
### Parent-child communication <sup data-p="d">use with caution</sup>
1592+
### 父子组件通信 <sup data-p="d">谨慎使用</sup>
15931593

1594-
**Props and events should be preferred for parent-child component communication, instead of `this.$parent` or mutating props.**
1594+
**应该优先通过 prop 和事件进行父子组件之间的通信,而不是 `this.$parent` 或改变 prop。**
15951595

1596-
An ideal Vue application is props down, events up. Sticking to this convention makes your components much easier to understand. However, there are edge cases where prop mutation or `this.$parent` can simplify two components that are already deeply coupled.
1596+
一个理想的 Vue 应用是 prop 向下传递,事件向上传递的。遵循这一约定会让你的组件更易于理解。然而,在一些边界情况下 prop 的变更或 `this.$parent` 能够简化两个深度耦合的组件。
15971597

1598-
The problem is, there are also many _simple_ cases where these patterns may offer convenience. Beware: do not be seduced into trading simplicity (being able to understand the flow of your state) for short-term convenience (writing less code).
1598+
问题在于,这种做法在很多_简单_的场景下可能会更方便。但请当心,不要为了一时方便 (少写代码) 而牺牲数据流向的简洁性 (易于理解)。
15991599

16001600
{% raw %}<div class="style-example example-bad">{% endraw %}
16011601
#### 反例
@@ -1682,11 +1682,11 @@ Vue.component('TodoItem', {
16821682

16831683

16841684

1685-
### Global state management <sup data-p="d">use with caution</sup>
1685+
### 全局状态管理 <sup data-p="d">谨慎使用</sup>
16861686

1687-
**[Vuex](https://github.com/vuejs/vuex) should be preferred for global state management, instead of `this.$root` or a global event bus.**
1687+
**应该优先通过 [Vuex](https://github.com/vuejs/vuex) 管理全局状态,而不是通过 `this.$root` 或一个全局事件总线。**
16881688

1689-
Managing state on `this.$root` and/or using a [global event bus](../guide/migration.html#dispatch-和-broadcast-替换) can be convenient for very simple cases, but are not appropriate for most applications. Vuex offers not only a central place to manage state, but also tools for organizing, tracking, and debugging state changes.
1689+
通过 `this.$root` 和/或[全局事件总线](../guide/migration.html#dispatch-和-broadcast-替换)管理状态在很多简单的情况下都是很方便的,但是并不适用于绝大多数的应用。Vuex 提供的不仅是一个管理状态的中心区域,还是组织、追踪和调试状态变更的好工具。
16901690

16911691
{% raw %}</details>{% endraw %}
16921692

@@ -1769,14 +1769,14 @@ export default {
17691769
<script>
17701770
(function () {
17711771
var enforcementTypes = {
1772-
none: '<span title="There is unfortunately no way to automatically enforce this rule.">self-discipline</span>',
1773-
runtime: 'runtime error',
1772+
none: '<span title="这一规则无法强制执行">自律</span>',
1773+
runtime: '运行时错误',
17741774
linter: '<a href="https://github.com/vuejs/eslint-plugin-vue#eslint-plugin-vue" target="_blank">plugin:vue/recommended</a>'
17751775
}
17761776
Vue.component('sg-enforcement', {
17771777
template: '\
17781778
<span>\
1779-
<strong>Enforcement</strong>:\
1779+
<strong>强制执行</strong>:\
17801780
<span class="style-rule-tag" v-html="humanType"/>\
17811781
</span>\
17821782
',

0 commit comments

Comments
 (0)