-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Synced recent updates to #dee0bfd #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,15 +105,19 @@ type: api | |
|
||
### ignoredElements | ||
|
||
- **类型**:`Array<string>` | ||
- **类型**:`Array<string | RegExp>` | ||
|
||
- **默认值**:`[]` | ||
|
||
- **用法**: | ||
|
||
``` js | ||
Vue.config.ignoredElements = [ | ||
'my-custom-web-component', 'another-web-component' | ||
'my-custom-web-component', | ||
'another-web-component', | ||
// 用一个 `RegExp` 忽略所有“ion-”开头的元素 | ||
// 2.5+ only | ||
/^ion-/ | ||
] | ||
``` | ||
|
||
|
@@ -590,7 +594,8 @@ type: api | |
data: { | ||
a: 1, | ||
b: 2, | ||
c: 3 | ||
c: 3, | ||
d: 4 | ||
}, | ||
watch: { | ||
a: function (val, oldVal) { | ||
|
@@ -602,6 +607,11 @@ type: api | |
c: { | ||
handler: function (val, oldVal) { /* ... */ }, | ||
deep: true | ||
}, | ||
// 该回调将会在监听开始之后被立即调用 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 侦听? |
||
d: { | ||
handler: function (val, oldVal) { /* ... */ }, | ||
immediate: true | ||
} | ||
} | ||
}) | ||
|
@@ -845,6 +855,28 @@ type: api | |
|
||
- **参考**:[生命周期图示](../guide/instance.html#生命周期图示) | ||
|
||
### errorCaptured | ||
|
||
> 2.5.0+ 新增 | ||
|
||
- **类型**:`(err: Error, vm: Component, info: string) => ?boolean` | ||
|
||
- **详细**: | ||
|
||
当捕获一个来自子孙组件的错误时被调用。此钩子会收到三个参数:错误本身、发生错误的组件实例以及一个包含错误来源信息的字符串。此钩子可以返回 `false` 以阻止该错误继续向上传播。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 错误本身 → 错误对象? |
||
|
||
<p class="tip">你可以在此钩子中修改组件的状态。因此在你的模板或渲染函数中设置其它内容的短路条件非常重要,它可以防止当一个错误被捕获时该组件抛出一个无限的渲染循环。</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 去掉“你的”? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. “……组件进入一个无限的渲染循环”? |
||
|
||
**错误传播规则** | ||
|
||
- 默认情况下,如果全局的 `config.errorHandler` 被定义,所有的错误仍会发送它,因此这些错误仍让会向单一的分析服务的地方进行汇报。 | ||
|
||
- 如果一个组件的继承或父级从属链路中存在多个 `errorCaptured` 钩子,则它们将会被相同的错误同时唤起。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [原文问题] 我觉得“同时”有问题,应该说明顺序? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 恩,我觉得可以先在原文讨论,我这暂时改成“逐个唤起” |
||
|
||
- 如果此 `errorCaptured` 钩子自身抛出了一个错误,则这个新错误和原本被捕获的错误都会发送给全局的 `config.errorHandler`。 | ||
|
||
- 一个 `errorCaptured` 钩子能够返回 `false` 以阻止错误继续向上传播。本质上是说“这个错误已经被搞定了且应该被忽略”。它会阻止其它任何会被这个错误唤起的 `errorCaptured` 钩子和全局的 `config.errorHandler`。 | ||
|
||
## 选项 / 资源 | ||
|
||
### directives | ||
|
@@ -942,7 +974,7 @@ type: api | |
|
||
- **类型**: | ||
- **provide**:`Object | () => Object` | ||
- **inject**:`Array<string> | { [key: string]: string | Symbol }` | ||
- **inject**:`Array<string> | { [key: string]: string | Symbol | Object }` | ||
|
||
- **详细**: | ||
|
||
|
@@ -1024,6 +1056,42 @@ type: api | |
} | ||
``` | ||
|
||
> 在 2.5.0+ 的注入可以通过设置默认值使其变成可选项: | ||
|
||
``` js | ||
const Child = { | ||
inject: { | ||
foo: { default: 'foo' } | ||
} | ||
} | ||
``` | ||
|
||
如果它需要从一个不同名字的属性注入,则使用 `from` 来表示其源属性: | ||
|
||
``` js | ||
const Child = { | ||
inject: { | ||
foo: { | ||
from: 'bar', | ||
default: 'foo' | ||
} | ||
} | ||
} | ||
``` | ||
|
||
对于 prop 的默认值来说是类似的,你需要对非原始值使用一个工厂方法: | ||
|
||
``` js | ||
const Child = { | ||
inject: { | ||
foo: { | ||
from: 'bar', | ||
default: () => [1, 2, 3] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## 选项 / 其它 | ||
|
||
### name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ order: 402 | |
- **不支持 CSS (No CSS support)** 意味着当 HTML 和 JavaScript 组件化时,CSS 明显被遗漏 | ||
- **没有构建步骤 (No build step)** 限制只能使用 HTML 和 ES5 JavaScript, 而不能使用预处理器,如 Pug (formerly Jade) 和 Babel | ||
|
||
文件扩展名为 `.vue` 的 **single-file components(单文件组件)** 为以上所有问题提供了解决方法,并且还可以使用 Webpack 或 Browserify 等构建工具。 | ||
文件扩展名为 `.vue` 的 **single-file components(单文件组件)** 为以上所有问题提供了解决方法,并且还可以使用 webpack 或 Browserify 等构建工具。 | ||
|
||
这是一个文件名为 `Hello.vue` 的简单实例: | ||
|
||
|
@@ -31,7 +31,7 @@ order: 402 | |
|
||
<img src="/images/vue-component-with-preprocessors.png" style="display: block; margin: 30px auto;"> | ||
|
||
这些特定的语言只是例子,你可以只是简单地使用 Babel,TypeScript,SCSS,PostCSS - 或者其他任何能够帮助你提高生产力的预处理器。如果搭配 `vue-loader` 使用 Webpack,它也是把 CSS Modules 当作第一公民来对待的。 | ||
这些特定的语言只是例子,你可以只是简单地使用 Babel,TypeScript,SCSS,PostCSS - 或者其他任何能够帮助你提高生产力的预处理器。如果搭配 `vue-loader` 使用 webpack,它也是把 CSS Modules 当作第一公民来对待的。 | ||
|
||
### 怎么看待关注点分离? | ||
|
||
|
@@ -50,6 +50,10 @@ order: 402 | |
|
||
## 起步 | ||
|
||
### 例子沙箱 | ||
|
||
如果你希望深入了解并开始使用单文件组件,请来 CodeSandbox [看看这个简单的 todo 应用](https://codesandbox.io/s/o29j95wx9)。 | ||
|
||
### 针对刚接触 JavaScript 模块开发系统的用户 | ||
|
||
有了 `.vue` 组件,我们就进入了高级 JavaScript 应用领域。如果你没有准备好的话,意味着还需要学会使用一些附加的工具: | ||
|
@@ -58,14 +62,12 @@ order: 402 | |
|
||
- **Modern JavaScript with ES2015/16**:阅读 Babel 的 [Learn ES2015 guide](https://babeljs.io/docs/learn-es2015/)。你不需要立刻记住每一个方法,但是你可以保留这个页面以便后期参考。 | ||
|
||
在你花一些时日了解这些资源之后,我们建议你参考 [webpack-simple](https://github.com/vuejs-templates/webpack-simple)。只要遵循指示,你就能很快地运行一个用到 `.vue` 组件,ES2015 和 热重载 (hot-reloading) 的 Vue 项目! | ||
|
||
这个模板使用 [Webpack](https://webpack.github.io/),一个能将多个模块打包成最终应用的模块打包工具。想学习更多 Webpack 的知识,请移步[它们的官方文档](https://webpack.js.org/configuration/)以及 [Webpack Academy](https://webpack.academy/p/the-core-concepts)。 | ||
在你花一些时日了解这些资源之后,我们建议你参考 [webpack](https://github.com/vuejs-templates/webpack)。只要遵循指示,你就能很快地运行一个用到 `.vue` 组件,ES2015 和 热重载 (hot-reloading) 的 Vue 项目! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. “热重载”前多了个空格 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这里“take a day”译为“一些时日”好像不是很准确?“一些时日”感觉是比较长的一段时间。 还有一处:“……建议你参考 webpack 模板。” There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 就直译为“一天时间”吧 |
||
|
||
在 Webpack 中,每个模块被打包到 bundle 之前都由一个相应的 "loader" 来转换,Vue 也提供 [vue-loader](https://github.com/vuejs/vue-loader) 插件来执行 `.vue` 单文件组件 的转换。这个 [webpack-simple](https://github.com/vuejs-templates/webpack-simple) 模板已经为你准备好了所有的东西,但是如果你想了解更多关于 `.vue` 组件和 Webpack 如何一起运转的信息,你可以阅读 [vue-loader 的文档](https://vue-loader.vuejs.org)。 | ||
想学习更多 webpack 的知识,请移步[它们的官方文档](https://webpack.js.org/configuration/)以及 [webpack learning academy](https://webpack.academy/p/the-core-concepts)。在 webpack 中,每个模块被打包到 bundle 之前都由一个相应的 "loader" 来转换,Vue 也提供 [vue-loader](https://github.com/vuejs/vue-loader) 插件来执行 `.vue` 单文件组件 的转换。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "loader" → “loader” |
||
|
||
### 针对高级用户 | ||
|
||
无论你更钟情 Webpack 或是 Browserify,我们为简单的和更复杂的项目都提供了一些文档模板。我们建议浏览 [github.com/vuejs-templates](https://github.com/vuejs-templates),找到你需要的部分,然后参考 README 中的说明,使用 [vue-cli](https://github.com/vuejs/vue-cli) 工具生成新的项目。 | ||
无论你更钟情 webpack 或是 Browserify,我们为简单的和更复杂的项目都提供了一些文档模板。我们建议浏览 [github.com/vuejs-templates](https://github.com/vuejs-templates),找到你需要的部分,然后参考 README 中的说明,使用 [vue-cli](https://github.com/vuejs/vue-cli) 工具生成新的项目。 | ||
|
||
模板中使用 [Webpack](https://webpack.js.org/),一个模块加载器加载多个模块然后构建成最终应用。为了进一步了解 Webpack,可以看 [官方介绍视频](https://www.youtube.com/watch?v=WQue1AN93YU)。如果你有基础,可以看 [在 Egghead.io 上的 Webpack 进阶教程](https://egghead.io/courses/using-webpack-for-production-javascript-applications)。 | ||
模板中使用 [webpack](https://webpack.js.org/),一个模块加载器加载多个模块然后构建成最终应用。为了进一步了解 webpack,可以看 [官方介绍视频](https://www.youtube.com/watch?v=WQue1AN93YU)。如果你有基础,可以看 [在 Egghead.io 上的 webpack 进阶教程](https://egghead.io/courses/using-webpack-for-production-javascript-applications)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
仅在 2.5+ 支持?