You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
{% raw %}<divclass="style-example example-bad">{% endraw %}
1503
1503
#### 反例
1504
1504
1505
1505
```html
1506
1506
<divv-if="error">
1507
-
Error: {{ error }}
1507
+
错误:{{ error }}
1508
1508
</div>
1509
1509
<divv-else>
1510
1510
{{ results }}
@@ -1517,7 +1517,7 @@ By default, Vue updates the DOM as efficiently as possible. That means when swit
1517
1517
1518
1518
```html
1519
1519
<divv-if="error"key="search-status">
1520
-
Error: {{ error }}
1520
+
错误:{{ error }}
1521
1521
</div>
1522
1522
<divv-elsekey="search-results">
1523
1523
{{ results }}
@@ -1526,7 +1526,7 @@ By default, Vue updates the DOM as efficiently as possible. That means when swit
1526
1526
1527
1527
```html
1528
1528
<pv-if="error">
1529
-
Error: {{ error }}
1529
+
错误:{{ error }}
1530
1530
</p>
1531
1531
<divv-else>
1532
1532
{{ results }}
@@ -1536,11 +1536,11 @@ By default, Vue updates the DOM as efficiently as possible. That means when swit
1536
1536
1537
1537
1538
1538
1539
-
### Element selectors with `scoped` <supdata-p="d">use with caution</sup>
1539
+
### `scoped`中的元素选择器 <supdata-p="d">谨慎使用</sup>
1540
1540
1541
-
**Element selectors should be avoided with `scoped`.**
1541
+
**元素选择器应该避免在 `scoped` 中出现。**
1542
1542
1543
-
Prefer class selectors over element selectors in `scoped`styles, because large numbers of element selectors are slow.
1543
+
在 `scoped`样式中,类选择器比元素选择器更好,因为大量使用元素选择器是很慢的。
1544
1544
1545
1545
{% raw %}
1546
1546
<details>
@@ -1549,9 +1549,9 @@ Prefer class selectors over element selectors in `scoped` styles, because large
1549
1549
</summary>
1550
1550
{% endraw %}
1551
1551
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]`).
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.
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.
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).
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.
0 commit comments