Skip to content

Commit 1578f40

Browse files
committed
Sync updates from vuejs.org.
From: 8b7db5e380478a6876b8b3a4fb79c7654729421f (2.3.0) to: c7a2852fd4aa1847738d343c813bf422b09e5dff Except guide/comparison.md (this file will be updated separately).
1 parent a5e1002 commit 1578f40

File tree

11 files changed

+141
-85
lines changed

11 files changed

+141
-85
lines changed

src/v2/api/index.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ type: api
11981198

11991199
- **用法:**
12001200

1201-
移除事件监听器
1201+
移除自定义事件监听器
12021202

12031203
- 如果没有提供参数,则移除所有的事件监听器;
12041204

@@ -1762,6 +1762,31 @@ type: api
17621762

17631763
- **参考:** [具名 Slots](../guide/components.html#具名-Slot)
17641764

1765+
### is
1766+
1767+
- **Expects:** `string`
1768+
1769+
Used for [dynamic components](../guide/components.html#Dynamic-Components) and to work around [limitations of in-DOM templates](../guide/components.html#DOM-Template-Parsing-Caveats).
1770+
1771+
For example:
1772+
1773+
``` html
1774+
<!-- component changes when currentView changes -->
1775+
<component v-bind:is="currentView"></component>
1776+
1777+
<!-- necessary because <my-row> would be invalid inside -->
1778+
<!-- a <table> element and so would be hoisted out -->
1779+
<table>
1780+
<tr is="my-row"></tr>
1781+
</table>
1782+
```
1783+
1784+
For detailed usage, follow the links in the description above.
1785+
1786+
- **See also:**
1787+
- [Dynamic Components](../guide/components.html#Dynamic-Components)
1788+
- [DOM Template Parsing Caveats](../guide/components.html#DOM-Template-Parsing-Caveats)
1789+
17651790
## 内置的组件
17661791

17671792
### component
@@ -1909,6 +1934,8 @@ type: api
19091934
</transition>
19101935
```
19111936

1937+
Note, `<keep-alive>` is designed for the case where it has one direct child component that is being toggled. It does not work if you have `v-for` inside it. When there are multiple conditional children, as above, `<keep-alive>` requires that only one child is rendered at a time.
1938+
19121939
- **`include` and `exclude`**
19131940

19141941
> 2.1.0 新增

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ data: {
202202
<div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }">
203203
```
204204

205+
This will only render the last value in the array which the browser supports. In this example, it will render `display: flex` for browsers that support the unprefixed version of flexbox.
206+
205207
***
206208

207209
> 原文:http://vuejs.org/guide/class-and-style.html

src/v2/guide/components.md

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ Vue.component('example', {
426426
- Function
427427
- Object
428428
- Array
429+
- Symbol
429430

430431
`type` 也可以是一个自定义构造器函数,使用 `instanceof` 检测。
431432

@@ -611,7 +612,12 @@ Vue.component('currency-input', {
611612
// 删除两侧的空格符
612613
.trim()
613614
// 保留 2 小数位
614-
.slice(0, value.indexOf('.') + 3)
615+
.slice(
616+
0,
617+
value.indexOf('.') === -1
618+
? value.length
619+
: value.indexOf('.') + 3
620+
)
615621
// 如果值不统一,手动覆盖以保持一致
616622
if (formattedValue !== value) {
617623
this.$refs.input.value = formattedValue
@@ -644,7 +650,12 @@ Vue.component('currency-input', {
644650
updateValue: function (value) {
645651
var formattedValue = value
646652
.trim()
647-
.slice(0, value.indexOf('.') + 3)
653+
.slice(
654+
0,
655+
value.indexOf('.') === -1
656+
? value.length
657+
: value.indexOf('.') + 3
658+
)
648659
if (formattedValue !== value) {
649660
this.$refs.input.value = formattedValue
650661
}
@@ -665,14 +676,43 @@ new Vue({
665676

666677
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/1oqjojjx/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
667678

668-
事件接口不仅仅可以用来连接组件内部的表单输入,也很容易集成你自己创造的输入类型。想象一下:
679+
### Customizing Component `v-model`
680+
681+
> New in 2.2.0
682+
683+
By default, `v-model` on a component uses `value` as the prop and `input` as the event, but some input types such as checkboxes and radio buttons may want to use the `value` prop for a different purpose. Using the `model` option can avoid the conflict in such cases:
684+
685+
``` js
686+
Vue.component('my-checkbox', {
687+
model: {
688+
prop: 'checked',
689+
event: 'change'
690+
},
691+
props: {
692+
checked: Boolean,
693+
// this allows using the `value` prop for a different purpose
694+
value: String
695+
},
696+
// ...
697+
})
698+
```
699+
700+
``` html
701+
<my-checkbox v-model="foo" value="some value"></my-checkbox>
702+
```
703+
704+
The above will be equivalent to:
669705

670706
``` html
671-
<voice-recognizer v-model="question"></voice-recognizer>
672-
<webcam-gesture-reader v-model="gesture"></webcam-gesture-reader>
673-
<webcam-retinal-scanner v-model="retinalImage"></webcam-retinal-scanner>
707+
<my-checkbox
708+
:checked="foo"
709+
@change="val => { foo = val }"
710+
value="some value">
711+
</my-checkbox>
674712
```
675713

714+
<p class="tip">Note that you still have to declare the `checked` prop explicitly.</p>
715+
676716
### 非父子组件通信
677717

678718
有时候两个组件也需要通信(非父子关系)。在简单的场景下,可以使用一个空的 Vue 实例作为中央事件总线:
@@ -1071,7 +1111,7 @@ const AsyncComp = () => ({
10711111

10721112
### 组件命名约定
10731113

1074-
当注册组件(或者 props)时,可以使用 kebab-case ,camelCase ,或 TitleCase 。Vue 不关心这个
1114+
当注册组件(或者 props)时,可以使用 kebab-case,camelCase,或 PascalCase
10751115

10761116
``` js
10771117
// 在组件定义中
@@ -1080,8 +1120,8 @@ components: {
10801120
'kebab-cased-component': { /* ... */ },
10811121
// register using camelCase
10821122
'camelCasedComponent': { /* ... */ },
1083-
// register using TitleCase
1084-
'TitleCasedComponent': { /* ... */ }
1123+
// register using PascalCase
1124+
'PascalCasedComponent': { /* ... */ }
10851125
}
10861126
```
10871127

@@ -1094,15 +1134,33 @@ components: {
10941134
<pascal-cased-component></pascal-cased-component>
10951135
```
10961136

1097-
当使用字符串模式时,可以不受 HTML 的 case-insensitive 限制。这意味实际上在模版中,你可以使用 camelCase 、 TitleCase 或者 kebab-case 来引用:
1137+
当使用字符串模式时,可以不受 HTML 的 case-insensitive 限制。这意味实际上在模版中,你可以使用下面的方式来引用你的组件:
1138+
1139+
- kebab-case
1140+
- camelCase 或 kebab-case 如果组件已经被定义为 camelCase
1141+
- kebab-case,camelCase 或 PascalCase 如果组件已经被定义为 PascalCase
1142+
1143+
``` js
1144+
components: {
1145+
'kebab-cased-component': { /* ... */ },
1146+
camelCasedComponent: { /* ... */ },
1147+
PascalCasedComponent: { /* ... */ }
1148+
}
1149+
```
10981150

10991151
``` html
1100-
<!-- 在字符串模版中可以用任何你喜欢的方式! -->
1101-
<my-component></my-component>
1102-
<myComponent></myComponent>
1103-
<MyComponent></MyComponent>
1152+
<kebab-cased-component></kebab-cased-component>
1153+
1154+
<camel-cased-component></camel-cased-component>
1155+
<camelCasedComponent></camelCasedComponent>
1156+
1157+
<pascal-cased-component></pascal-cased-component>
1158+
<pascalCasedComponent></pascalCasedComponent>
1159+
<PascalCasedComponent></PascalCasedComponent>
11041160
```
11051161

1162+
这意味着 PascalCase 是最通用的 _声明约定_ 而 kebab-case 是最通用的 _使用约定_
1163+
11061164
如果组件未经 `slot` 元素传递内容,你甚至可以在组件名后使用 `/` 使其自闭合:
11071165

11081166
``` html

src/v2/guide/forms.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ new Vue({
3838

3939
``` html
4040
<span>Multiline message is:</span>
41-
<p style="white-space: pre">{{ message }}</p>
41+
<p style="white-space: pre-line">{{ message }}</p>
4242
<br>
4343
<textarea v-model="message" placeholder="add multiple lines"></textarea>
4444
```
4545

4646
{% raw %}
4747
<div id="example-textarea">
4848
<span>Multiline message is:</span>
49-
<p style="white-space: pre">{{ message }}</p>
49+
<p style="white-space: pre-line">{{ message }}</p>
5050
<br>
5151
<textarea v-model="message" placeholder="add multiple lines"></textarea>
5252
</div>

src/v2/guide/index.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Vue.js(读音 /vjuː/,类似于 **view**) 是一套构建用户界面的**
1414

1515
<p class="tip">官方指南假设你已有 HTML、CSS 和 JavaScript 中级前端知识。如果你刚开始学习前端开发,将框架作为你的第一步可能不是最好的主意——掌握好基础知识再来!之前有其他框架的使用经验对于学习 Vue.js 是有帮助的,但这不是必需的。</p>
1616

17-
尝试 Vue.js 最简单的方法是使用 [JSFiddle Hello World 例子](https://jsfiddle.net/chrisvfritz/50wL7mdz/)。你可以在浏览器新标签页中打开它,跟着例子学习一些基础用法。或者你也可以创建一个本地的 `.html` 文件,然后通过如下方式引入 Vue:
17+
尝试 Vue.js 最简单的方法是使用 [JSFiddle Hello World 例子](https://jsfiddle.net/chrisvfritz/50wL7mdz/)。你可以在浏览器新标签页中打开它,跟着例子学习一些基础用法。或者你也可以<a href="https://gist.githubusercontent.com/chrisvfritz/7f8d7d63000b48493c336e48b3db3e52/raw/ed60c4e5d5c6fec48b0921edaed0cb60be30e87c/index.html" target="_blank" download="index.html">创建一个 <code>.html</code> 文件<a/>,然后通过如下方式引入 Vue:
1818

1919
``` html
2020
<script src="https://unpkg.com/vue/dist/vue.js"></script>
@@ -292,9 +292,16 @@ Vue.component('todo-item', {
292292
``` html
293293
<div id="app-7">
294294
<ol>
295-
<!-- 现在我们为每个todo-item提供待办项对象 -->
296-
<!-- 待办项对象是变量,即其内容可以是动态的 -->
297-
<todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
295+
<!--
296+
现在我们为每个 todo-item 提供待办项对象
297+
待办项对象是变量,即其内容可以是动态的。
298+
我们也需要为每个组件提供一个“key”,晚些时候我们会做个解释。
299+
-->
300+
<todo-item
301+
v-for="item in groceryList"
302+
v-bind:todo="item"
303+
v-bind:key="item.id">
304+
</todo-item>
298305
</ol>
299306
</div>
300307
```
@@ -309,17 +316,17 @@ var app7 = new Vue({
309316
el: '#app-7',
310317
data: {
311318
groceryList: [
312-
{ text: '蔬菜' },
313-
{ text: '奶酪' },
314-
{ text: '随便其他什么人吃的东西' }
319+
{ id: 0, text: '蔬菜' },
320+
{ id: 1, text: '奶酪' },
321+
{ id: 2, text: '随便其他什么人吃的东西' }
315322
]
316323
}
317324
})
318325
```
319326
{% raw %}
320327
<div id="app-7" class="demo">
321328
<ol>
322-
<todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
329+
<todo-item v-for="item in groceryList" v-bind:todo="item" :key="item.id"></todo-item>
323330
</ol>
324331
</div>
325332
<script>
@@ -331,9 +338,9 @@ var app7 = new Vue({
331338
el: '#app-7',
332339
data: {
333340
groceryList: [
334-
{ text: '蔬菜' },
335-
{ text: '奶酪' },
336-
{ text: '随便其他什么人吃的东西' }
341+
{ id: 0, text: '蔬菜' },
342+
{ id: 1, text: '奶酪' },
343+
{ id: 2, text: '随便其他什么人吃的东西' }
337344
]
338345
}
339346
})

src/v2/guide/list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ new Vue({
196196

197197
``` html
198198
<div>
199-
<span v-for="n in 10">{{ n }}</span>
199+
<span v-for="n in 10">{{ n }} </span>
200200
</div>
201201
```
202202

src/v2/guide/render-function.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ createElement(
104104
},
105105

106106
// {String | Array}
107-
 // 子节点(VNodes),可以是一个字符串或者一个数组. 可选参数.
107+
 // 子节点 (VNodes),由 `createElement()` 构建而成,
108+
// 或简单的使用字符串来生成“文本结点”。可选参数。
108109
[
109-
createElement('h1', 'hello world'),
110+
'先写一些文字',
111+
createElement('h1', '一则头条'),
110112
createElement(MyComponent, {
111113
props: {
112-
someProp: 'foo'
114+
someProp: 'foobar'
113115
}
114-
}),
115-
'bar'
116+
})
116117
]
117118
)
118119
```
@@ -160,7 +161,7 @@ createElement(
160161
 directives: [
161162
{
162163
name: 'my-custom-directive',
163-
value: '2'
164+
value: '2',
164165
expression: '1 + 1',
165166
arg: 'foo',
166167
modifiers: {
@@ -174,7 +175,7 @@ createElement(
174175
default: props => h('span', props.text)
175176
},
176177
 // 如果组件是其他组件的子组件,需为slot指定名称
177-
 slot: 'name-of-slot'
178+
 slot: 'name-of-slot',
178179
// 其他特殊顶层属性
179180
key: 'myKey',
180181
ref: 'myRef'
@@ -470,7 +471,7 @@ Vue.component('my-component', {
470471
- `data`: 传递给组件的 data 对象
471472
- `parent`: 对父组件的引用
472473
- `listeners`: (2.3.0+) 一个包含了组件上所注册的 `v-on` 侦听器的对象。这只是一个指向 `data.on` 的别名。
473-
- `injections`: (2.3.0+) 如果使用了 [`inject`](https://vuejs.org/v2/api/#provide-inject) 选项, 则该对象包含了应当被注入的属性。
474+
- `injections`: (2.3.0+) 如果使用了 [`inject`](../api/#provide-inject) 选项, 则该对象包含了应当被注入的属性。
474475

475476

476477
在添加 `functional: true` 之后,锚点标题组件的 render 函数之间简单更新增加 `context` 参数,`this.$slots.default` 更新为 `context.children`,之后`this.level` 更新为 `context.props.level`

src/v2/guide/state-management.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ var store = {
3939
message: 'Hello!'
4040
},
4141
setMessageAction (newValue) {
42-
this.debug && console.log('setMessageAction triggered with', newValue)
42+
if (this.debug) console.log('setMessageAction triggered with', newValue)
4343
this.state.message = newValue
4444
},
4545
clearMessageAction () {
46-
this.debug && console.log('clearMessageAction triggered')
46+
if (this.debug) console.log('clearMessageAction triggered')
4747
this.state.message = 'clearMessageAction triggered'
4848
}
4949
}

src/v2/guide/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Mustache 标签将会被替代为对应数据对象上 `msg` 属性的值。无
3636
<div v-html="rawHtml"></div>
3737
```
3838

39-
被插入的内容都会被当做 HTML —— 数据绑定会被忽略。注意,你不能使用 `v-html` 来复合局部模板,因为 Vue 不是基于字符串的模板引擎。组件更适合担任 UI 重用与复合的基本单元。
39+
这个 `div` 的内容将会被替换成为属性值 `rawHtml`,直接作为 HTML —— 数据绑定会被忽略。注意,你不能使用 `v-html` 来复合局部模板,因为 Vue 不是基于字符串的模板引擎。组件更适合担任 UI 重用与复合的基本单元。
4040

4141
<p class="tip">你的站点上动态渲染的任意 HTML 可能会非常危险,因为它很容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。请只对可信内容使用 HTML 插值,**绝不要**对用户提供的内容插值。</p>
4242

src/v2/guide/transitioning-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Vue 的过渡系统提供了非常多简单的方法设置进入、离开和列
1616

1717
## 状态动画 与 watcher
1818

19-
通过 watcher 我们能监听到任何数值属性的数值更新。可能听起来很抽象,所以让我们先来看看使用Tweenjs一个例子
19+
通过 watcher 我们能监听到任何数值属性的数值更新。可能听起来很抽象,所以让我们先来看看使用 [Tweenjs](https://github.com/tweenjs/tween.js) 一个例子
2020

2121
``` html
2222
<script src="https://unpkg.com/tween.js@16.3.4"></script>
@@ -88,7 +88,7 @@ new Vue({
8888
</script>
8989
{% endraw %}
9090

91-
当你把数值更新时,就会触发动画。这个是一个不错的演示,但是对于不能直接像数字一样存储的值,比如 CSS 中的 color 的值,通过下面的例子我们来通过 Color.js 实现一个例子:
91+
当你把数值更新时,就会触发动画。这个是一个不错的演示,但是对于不能直接像数字一样存储的值,比如 CSS 中的 color 的值,通过下面的例子我们来通过 [Color.js](https://github.com/brehaut/color-js) 实现一个例子:
9292

9393

9494
``` html

0 commit comments

Comments
 (0)