@@ -105,15 +105,19 @@ type: api
105
105
106
106
### ignoredElements
107
107
108
- - ** 类型** :` Array<string> `
108
+ - ** 类型** :` Array<string | RegExp > `
109
109
110
110
- ** 默认值** :` [] `
111
111
112
112
- ** 用法** :
113
113
114
114
``` js
115
115
Vue .config .ignoredElements = [
116
- ' my-custom-web-component' , ' another-web-component'
116
+ ' my-custom-web-component' ,
117
+ ' another-web-component' ,
118
+ // 用一个 `RegExp` 忽略所有“ion-”开头的元素
119
+ // 仅在 2.5+ 支持
120
+ / ^ ion-/
117
121
]
118
122
```
119
123
@@ -590,7 +594,8 @@ type: api
590
594
data: {
591
595
a: 1 ,
592
596
b: 2 ,
593
- c: 3
597
+ c: 3 ,
598
+ d: 4
594
599
},
595
600
watch: {
596
601
a : function (val , oldVal ) {
@@ -602,6 +607,11 @@ type: api
602
607
c: {
603
608
handler : function (val , oldVal ) { /* ... */ },
604
609
deep: true
610
+ },
611
+ // 该回调将会在侦听开始之后被立即调用
612
+ d: {
613
+ handler : function (val , oldVal ) { /* ... */ },
614
+ immediate: true
605
615
}
606
616
}
607
617
})
@@ -845,6 +855,28 @@ type: api
845
855
846
856
- **参考**:[生命周期图示](../guide/instance.html#生命周期图示)
847
857
858
+ ### errorCaptured
859
+
860
+ > 2.5.0+ 新增
861
+
862
+ - **类型**:` (err : Error , vm : Component , info : string ) => ? boolean`
863
+
864
+ - **详细**:
865
+
866
+ 当捕获一个来自子孙组件的错误时被调用。此钩子会收到三个参数:错误对象、发生错误的组件实例以及一个包含错误来源信息的字符串。此钩子可以返回 ` false ` 以阻止该错误继续向上传播。
867
+
868
+ <p class="tip">你可以在此钩子中修改组件的状态。因此在模板或渲染函数中设置其它内容的短路条件非常重要,它可以防止当一个错误被捕获时该组件进入一个无限的渲染循环。</p>
869
+
870
+ **错误传播规则**
871
+
872
+ - 默认情况下,如果全局的 ` config .errorHandler ` 被定义,所有的错误仍会发送它,因此这些错误仍让会向单一的分析服务的地方进行汇报。
873
+
874
+ - 如果一个组件的继承或父级从属链路中存在多个 ` errorCaptured` 钩子,则它们将会被相同的错误逐个唤起。
875
+
876
+ - 如果此 ` errorCaptured` 钩子自身抛出了一个错误,则这个新错误和原本被捕获的错误都会发送给全局的 ` config .errorHandler ` 。
877
+
878
+ - 一个 ` errorCaptured` 钩子能够返回 ` false ` 以阻止错误继续向上传播。本质上是说“这个错误已经被搞定了且应该被忽略”。它会阻止其它任何会被这个错误唤起的 ` errorCaptured` 钩子和全局的 ` config .errorHandler ` 。
879
+
848
880
## 选项 / 资源
849
881
850
882
### directives
@@ -942,7 +974,7 @@ type: api
942
974
943
975
- **类型**:
944
976
- **provide**:` Object | () => Object `
945
- - **inject**:` Array < string> | { [key: string]: string | Symbol }`
977
+ - **inject**:` Array < string> | { [key: string]: string | Symbol | Object }`
946
978
947
979
- **详细**:
948
980
@@ -1024,6 +1056,42 @@ type: api
1024
1056
}
1025
1057
` ` `
1026
1058
1059
+ > 在 2.5.0+ 的注入可以通过设置默认值使其变成可选项:
1060
+
1061
+ ` ` ` js
1062
+ const Child = {
1063
+ inject: {
1064
+ foo: { default: ' foo' }
1065
+ }
1066
+ }
1067
+ ` ` `
1068
+
1069
+ 如果它需要从一个不同名字的属性注入,则使用 ` from` 来表示其源属性:
1070
+
1071
+ ` ` ` js
1072
+ const Child = {
1073
+ inject: {
1074
+ foo: {
1075
+ from: ' bar' ,
1076
+ default: ' foo'
1077
+ }
1078
+ }
1079
+ }
1080
+ ` ` `
1081
+
1082
+ 对于 prop 的默认值来说是类似的,你需要对非原始值使用一个工厂方法:
1083
+
1084
+ ` ` ` js
1085
+ const Child = {
1086
+ inject: {
1087
+ foo: {
1088
+ from: ' bar' ,
1089
+ default : () => [1 , 2 , 3 ]
1090
+ }
1091
+ }
1092
+ }
1093
+ ` ` `
1094
+
1027
1095
## 选项 / 其它
1028
1096
1029
1097
### name
0 commit comments