diff --git a/Makefile b/Makefile index 3fc827c410..a0d74bbd9a 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,14 @@ all: update deploy deploy: - rm -f db.json + rm -rf public db.json hexo generate - cp -R ./todomvc public/examples hexo deploy update: cd ../vue && \ git checkout -- dist && \ - git checkout next && \ + git checkout dev && \ npm run build cp ../vue/dist/vue.min.js themes/vue/source/js/vue.min.js cp ../vue/dist/vue.js themes/vue/source/js/vue.js diff --git a/README.md b/README.md index 37ecaecb30..1b7a6a0dd9 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,132 @@ -# vuejs-2.0 翻译计划 +# Vue.js 2.0 翻译 +这个厂库只用来协作翻译 -## 翻译字典 +[vue2 文档厂库](https://github.com/hayeah/vuejs.org) -先参考 [vuejs-1.0 中文文档](http://cn.vuejs.org/),如有需要再建立一个额外的文档。 +## 翻译规范(参考了 [vue 1.0 翻译规范](https://github.com/vuejs/cn.vuejs.org/blob/lang-zh/CONTRIBUTING.md#翻译) ) +* 使用中文的符号 +* 汉字,字母,数字等之间以空格隔开。 +* 专有词注意大小写,如 HTML,CSS,JavaScript。 +* 代码只翻译注释。 + +[阮一峰关于中文技术文档的规范](https://github.com/ruanyf/document-style-guide) + +## 翻译字典(更新中) + +英文 | 中文 | 备注 | +---- | ---- | ---- | +(single) source of truth | (单一)数据源 +attribute | 属性 | 主体: DOM 元素 +benchmark | 测试基准 +companion library | 插件库 +component | 组件 +console | 控制台 +core | 内核 +declarative | 声明式 +directive | 指令 +example | 示例 +fallback content | 替换内容 | 根据 MDN 文档 +filter | 过滤器 +for example | 例如 +functional | 函数式 | e.g. `functional component` :函数式组件 +guide | 教程 +incrementally adoptable | 增量式使用(转为动词) +interpolation | 插值 +item | 项 | e.g. 列表项,数组项 +learning curve | 学习曲线 +listener, listen | 侦听器;侦听 +mutation | 突变 +non-trivial app | 正常应用 +overhead | 额外开销 +parent scope | 父级作用域 +progressive | 渐进式 +prop | 属性 | 主体:Vue 组件 +property | 属性 | 主体:javascript 对象 +reactive | 响应式的 +render function | 渲染函数 +see also | 另见 +single page application, spa | 单页应用 +transition effect | 过渡动画 +transition | 过渡动画 | [小右的文章](http://www.html-js.com/article/1833) +virtual DOM | 虚拟 DOM +wrap | 包裹 + +参考资料: +- [小右的专栏](http://www.html-js.com/article/column/99) +- [小右的另一个专栏](http://www.zhihu.com.question.39879941.cmiiu.com/?people/evanyou/posts) +- [小右对 Vue 2 的介绍@Qcon](http://www.infoq.com/cn/articles/vue-2-progressive-front-end-solution) +- [vuejs-1.0 中文文档](http://cn.vuejs.org/) + ## 协作形式 翻译者: -* 请从标记为 `待领取` 的 issues 中领取任务,写清楚预估的 DDL。 +* 请从标记为 `待领取` 的 issues 中领取任务,写什么时候能完成。 * 如果超过预估时间无法完成请在 issue 中 at 协调员,说明接替者信息或请协调员重新分配该任务; * 完成任务后提交 PR -* 若 PR 被标记为 `待修改`,根据修改一件修改后删除标记,分配给协调员 +* 若 PR 被标记为 `待修改`,根据反馈修改后删除标记,分配给协调员 +* 请保留英文原文,方便校对。 + +协调员:[@hymRedemption](https://github.com/hymRedemption) -协调员 * 将无状态的 PR 分配给校对员,标记为待校对 * 若 `待合并` 的 PR 可以合并,则直接合并。合并后在 README 更新进度表,关闭相关的 issues * 若 `待合并` 的 PR 不能合并,分配给 PR 提交者并将 PR 标记为 `待修改` -校对员: +校对员: [@Egoist](https://github.com/egoist), [@mrwiredancer](https://github.com/Mr-Wiredancer) + * 对 `待校对` 的 PR 进行校对 * 校对通过则将 PR 改为`待合并`,并分配给协调员 * 校对不通过则将 PR 改为 `待修改`,并分配给 PR 提交者 -## 进度表 -文章 | 翻译 | 校对 | 状态 | ----- | ---- | ---- | ---- | -示例/示例| [mrwiredancer](https://github.com/Mr-Wiredancer) | | 进行中 | -api/index| -guide/class-and-style| -guide/comparison | -guide/components | - -#vuejs.org - -This site is built with [hexo](http://hexo.io/). Site content is written in Markdown format located in `src`. Pull requests welcome! +## 进度表 (最后更新:2016-10-28 15:22) -## Developing - -Start a dev server at `localhost:4000`: - -``` -$ npm install -g hexo-cli -$ npm install -$ hexo server -``` +文章 | 翻译 | 校对 | 状态 | +---- | ---- | ---- | ---- | +api/index#Global Config | [mrwiredancer](https://github.com/Mr-Wiredancer) | egoist | ~~已完成~~ +api/index#Global API | pandazki |[mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +api/index#Options/Data |[milkmeowo](https://github.com/milkmeowo)| egoist| ~~已完成~~ +api/index#Options/DOM |[milkmeowo](https://github.com/milkmeowo)| [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +api/index#Options/Lifecycle Hooks |[milkmeowo](https://github.com/milkmeowo)| hayeah | ~~已完成~~ +api/index#Options/Assets|[milkmeowo](https://github.com/milkmeowo)| [mrwiredancer](https://github.com/Mr-Wiredancer)| ~~已完成~~ +api/index#Options/misc |[milkmeowo](https://github.com/milkmeowo)| hayeah | ~~已完成~~ +api/index#Instance Properties | [dmxj](https://github.com/dmxj) |[mrwiredancer](https://github.com/Mr-Wiredancer)| ~~已完成~~ +api/index#Instance Methods/Data | [alfredcc](https://github.com/alfredcc) |egoist| ~~已完成~~ +api/index#Instance Methods/Eevents |[dmxj](https://github.com/dmxj)| [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +api/index#Instance Methods/Lifecycle |[dmxj](https://github.com/dmxj)|[mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +api/index#Directives |[dmxj](https://github.com/dmxj)|[mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +api/index#Special Attributes |[aliencyl7](https://github.com/aliencyl7)| [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +api/index#Built-in Components |[milkmeowo](https://github.com/milkmeowo)| [mrwiredancer](https://github.com/Mr-Wiredancer)|~~已完成~~ +api/index#VNode Interface |[milkmeowo](https://github.com/milkmeowo)| | ~~已完成~~ +api/index#Server-Side Rendering |[milkmeowo](https://github.com/milkmeowo)| hayeah | ~~已完成~~ +guide/installation | [mrwiredancer](https://github.com/Mr-Wiredancer) | egoist | ~~已完成~~ +guide/index | [mrwiredancer](https://github.com/Mr-Wiredancer) |pandazki | ~~已完成~~ +guide/instance | [baurine](https://github.com/baurine)| [mrwiredancer](https://github.com/Mr-Wiredancer)| ~~已完成~~ +guide/syntax |[baurine](https://github.com/baurine)|milkmeowo| ~~已完成~~ +guide/computed |[gongph](https://github.com/gongph) |[mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +guide/class-and-style | fszer | [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +guide/conditional |[MechanicianW](https://github.com/MechanicianW) | hayeah | ~~已完成~~ +guide/list | [mrwiredancer](https://github.com/Mr-Wiredancer) | coderkwong | ~~已完成~~ +guide/events | [mrwiredancer](https://github.com/Mr-Wiredancer) | [milkmeowo](https://github.com/milkmeowo)| ~~已完成~~ +guide/forms | jacelynfish | milmeowo | ~~已完成~~ +guide/components |[MechanicianW](https://github.com/MechanicianW) |[mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +guide/transitions | jacelynfish | codekwong, mrwiredancer | ~~已完成~~ +guide/transitioning-state |[gongph](https://github.com/gongph)| [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +guide/render-function | [pandazki](https://github.com/pandazki) | [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +guide/reactivity |[pandazki](https://github.com/pandazki) |[mrwiredancer](https://github.com/Mr-Wiredancer) |~~已完成~~ +guide/custom-directive |[lsslu](https://github.com/lsslu)| milkmeowo, [mrwiredancer](https://github.com/Mr-Wiredancer) |~~已完成~~ +guide/mixins | [leon0204](https://github.com/leon0204) | hayeah | ~~已完成~~ +guide/plugins |[leon0204](https://github.com/leon0204) | [milkmeowo](https://github.com/milkmeowo), hayeah|~~已完成~~ +guide/single-file-components | [mrwiredancer](https://github.com/Mr-Wiredancer) | [pandazki](https://github.com/pandazki) | ~~已完成~~ +guide/deployment | [mrwiredancer](https://github.com/Mr-Wiredancer) | coderkwong | ~~已完成~~ +guide/routing |[lsslu](https://github.com/lsslu)| [milkmeowo](https://github.com/milkmeowo), [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +guide/state-management | mrwiredancer | coderkwong | ~~已完成~~ +guide/unit-testing |[Yogi-Jiang](https://github.com/Yogi-Jiang) | hayeah | ~~已完成~~ +guide/ssr | gongph | [mrwiredancer](https://github.com/Mr-Wiredancer) | ~~已完成~~ +guide/migration |[RiXiong](https://github.com/RiXiong)| mrwiredancer|~~已完成~~ +guide/migration-vue-router |[mrwiredancer](https://github.com/Mr-Wiredancer) | [pandazki](https://github.com/pandazki) | ~~已完成~~ +guide/migration-vuex | [mrwiredancer](https://github.com/Mr-Wiredancer) | coderkwong | ~~已完成~~ +guide/comparison | [mrwiredancer](https://github.com/Mr-Wiredancer) | [milkmeowo](https://github.com/milkmeowo) | ~~已完成~~ +guide/join |[leon0204](https://github.com/leon0204)| [mrwiredancer](https://github.com/Mr-Wiredancer)| ~~已完成~~ diff --git a/_config.yml b/_config.yml index b886356dfc..182ed390e0 100644 --- a/_config.yml +++ b/_config.yml @@ -97,7 +97,7 @@ markdown: ## Docs: http://zespia.tw/hexo/docs/deployment.html deploy: type: git - repository: git@github.com:vuejs/rc.vuejs.org.git + repository: git@github.com:vuejs/vuejs.org.git feed: type: atom diff --git a/src/CNAME b/src/CNAME index 79fd262475..998cc417c8 100644 --- a/src/CNAME +++ b/src/CNAME @@ -1 +1 @@ -rc.vuejs.org +vuejs.org diff --git a/src/_posts/why-no-template-url.md b/src/_posts/why-no-template-url.md index fe40415646..f6fbabe2dd 100644 --- a/src/_posts/why-no-template-url.md +++ b/src/_posts/why-no-template-url.md @@ -13,7 +13,7 @@ First, it allows us to write our template in a separate HTML file. This gives us Second, because `templateURL` loads the template via Ajax at runtime, you don't need a build step in order to split up your files. This is convenient during development, but comes at a serious cost when you want to deploy it to production. Before HTTP/2 is universally supported, the number of HTTP requests is still probably the most critical factor in your app's initial load performance. Now imagine you use `templateURL` for every component in your app - the browser needs to perform dozens of HTTP requests before even being able to display anything! In case you don't know, most browsers limit the number of parallel requests it can perform to a single server. When you exceed that limit, your app's initial rendering will suffer for every extra round trip the browser has to wait for. Sure, there are build tools that can help you pre-register all those templates in `$templateCache` - but that shows us a build step is, in fact, inevitable for any serious frontend development. -So, without `templateURL`, how do we deal with the development experience problem? Writing templates as inline JavaScript strings is terrible, faking templates with ` + ``` Then you can start writing Vue code and even ship the minified version to production without feeling guilty or having to worry about performance problems. +然后你就可以开始写 Vue 代码,甚至可以把最小化的版本直接推到生产环境,完全不需要担心性能问题。 Since you don't need to know about JSX, ES2015, or build systems to get started with Vue, it also typically takes developers less than a day reading [the guide](/guide) to learn enough to build non-trivial applications. +要上手 Vue,你不需要了解 JSX,ES2015 或者构建系统。,通常你只需要花不到一天来阅读 [教程](/guide),就可以开始写一个实际应用。 -### Native Rendering +### 原生渲染 (Native Rendering) ReactNative enables you to write native-rendered apps for iOS and Android using the same React component model. This is great in that as a developer, you can apply your knowledge of a framework across multiple platforms. On this front, Vue has an official collaboration with [Weex](https://alibaba.github.io/weex/), a cross-platform UI framework developed by Alibaba Group, which uses Vue as its JavaScript framework runtime. This means with Weex, you can use the same Vue component syntax to author components that can not only be rendered in the Browser, but also natively on iOS and Android! +ReactNative 让你可以使用同样的 React 组件模型,编写原生渲染的 iOS 和 Android 应用。这对于开发者来说很棒,因为你可以用一个框架写跨平台的应用。在这一点上,Vue 已经和阿里巴巴的 [Weex](https://alibaba.github.io/weex/) 达成官方合作,Weex 会使用 Vue 来作为 JavaScript 的框架运行时。这意味着你可以在 Weex 中使用 Vue 的语法来编写部件,这些部件不仅可以在浏览器上运行,也可以在 iOS 和 Android 平台上以原生的方式运行。 -At this moment, Weex is still in active development and is not as mature and battle-tested as ReactNative, but its development is driven by the production needs by the largest e-commmerce business in the world, and the Vue team will also actively collaborate with the Weex team to ensure a smooth experience for Vue developers. +At this moment, Weex is still in active development and is not as mature and battle-tested as ReactNative, but its development is driven by the production needs of the largest e-commerce business in the world, and the Vue team will also actively collaborate with the Weex team to ensure a smooth experience for Vue developers. +在写这篇文章的时候,Weex 仍然处于活跃的开发状态,还没有达到 ReactNative 的成熟度,不过它的开发是由世界上最大的电子商务公司的生产需求所驱动的,而 Vue 团队也会积极地和 Weex 团队合作,确保为开发者带来流畅的体验。 -### With MobX +### 与 MobX 一起使用 (With MobX) MobX has become quite popular in the React community and it actually uses a nearly identical reactivity system to Vue. To a limited extent, the React + MobX workflow can be thought of as a more verbose Vue, so if you're using that combination and are enjoying it, jumping into Vue is probably the next logical step. +MobX 在 React 社区中已经相当流行,而且它使用了几乎跟 Vue 一摸一样的响应式系统。在某种程度上,可以把 React + Mobx 当作一个繁琐版的 Vue。所以如果你觉得这个组合用得很爽,那么使用 Vue 是一个很自然的选择。 ## Angular 1 Some of Vue's syntax will look very similar to Angular (e.g. `v-if` vs `ng-if`). This is because there were a lot of things that Angular got right and these were an inspiration for Vue very early in its development. There are also many pains that come with Angular however, where Vue has attempted to offer a significant improvement. +Vue 的一些语法看起来和 Angular 很类似(比如 `v-if` 和 `ng-if`)。这是因为 Angular 有很多做的很好的地方,而 Vue 在早期开发阶段从 Angular 获得了很多灵感。不过,使用 Angular 也有很多蛋疼的地方,而 Vue 在这些方面提供了大幅度的改善。 -### Complexity +### 复杂性 (Complexity) Vue is much simpler than Angular 1, both in terms of API and design. Learning enough to build non-trivial applications typically takes less than a day, which is not true for Angular 1. +无论是 API 还是设计思路,Vue 比 Angular 1 都要简单得多。使用 Vue 构建一个实际应用,只需要花不到一天的时间来学习,而 Angular 1 就不行了。 -### Flexibility and Modularity +### 灵活性和模块化 (Flexibility and Modularity) Angular 1 has strong opinions about how your applications should be structured, while Vue is a more flexible, modular solution. While this makes Vue more adaptable to a wide variety of projects, we also recognize that sometimes it's useful to have some decisions made for you, so that you can just get started coding. +Angular 1 对于你的项目结构有着很强的制约,而 Vue 则更为灵活且模块化。虽然这让 Vue 可以适应很多不同类型的项目,不过我们也意识到,有时候开发者不希望考虑太多,只是想直接开始写代码。 That's why we offer a [Webpack template](https://github.com/vuejs-templates/webpack) that can set you up within minutes, while also granting you access to advanced features such as hot module reloading, linting, CSS extraction, and much more. +这就是为什么我们提供了一个 [Webpack 模版](https://github.com/vuejs-templates/webpack),它可以在几分钟之内帮你配置好环境,同时提供了模块热加载,linting,CSS 提取等高级功能。 -### Data binding +### 数据绑定 (Data binding) Angular 1 uses two-way binding between scopes, while Vue enforces a one-way data flow between components. This makes the flow of data easier to reason about in non-trivial applications. +Angular 1 在不同域之间采用双向绑定,而 Vue 强制在组件之间使用单向数据流。这样会让应用的数据流更加清晰。 -### Directives vs Components +### 指令和组件 (Directives vs Components) Vue has a clearer separation between directives and components. Directives are meant to encapsulate DOM manipulations only, while components are self-contained units that have their own view and data logic. In Angular, there's a lot of confusion between the two. +Vue 清楚地区分了指令和组件。指令是用来封装 DOM 操作的,而组件是独立的存在,包含了自己的视图和数据逻辑。在 Angular 中,这两者经常会混在一起。 -### Performance +### 性能 (Performance) Vue has better performance and is much, much easier to optimize because it doesn't use dirty checking. Angular 1 becomes slow when there are a lot of watchers, because every time anything in the scope changes, all these watchers need to be re-evaluated again. Also, the digest cycle may have to run multiple times to "stabilize" if some watcher triggers another update. Angular users often have to resort to esoteric techniques to get around the digest cycle, and in some situations, there's simply no way to optimize a scope with many watchers. +Vue 有着更好的性能,并且更容易优化,因为 Vue 没有使用脏检查。Angular 1 在有大量监视器的时候会变的很慢,因为每一次在域内的变化,都会导致所有的监视器重新计算。而且,如果某些监视器触发了其它更新,那么 digest cycle 要多次计算才能得出最终的结果。Angular 的开发者经常需要用到一些黑魔法来绕开 digest cycle,而在某些情况下,根本没有办法对拥有多个监视器的域进行优化。 Vue doesn't suffer from this at all because it uses a transparent dependency-tracking observation system with async queueing - all changes trigger independently unless they have explicit dependency relationships. +而 Vue 就没有这个问题,因为 Vue 使用了一个透明的,基于异步队列的依赖跟踪观察系统,所有的变化都会独立触发,除非它们有明确的依赖关系。 Interestingly, there are quite a few similarities in how Angular 2 and Vue are addressing these Angular 1 issues. +有趣的是,Angular 2 和 Vue 用了不少相似的方式,来解决这些 Angular 1 的问题。 ## Angular 2 We have a separate section for Angular 2 because it really is a completely new framework. For example, it features a first-class component system, many implementation details have been completely rewritten, and the API has also changed quite drastically. +我们给 Angular 2 一个单独的篇幅,因为它是一个跟 Angular 1 完全不同的框架。比如,它具备一流的组件系统,许多实现细节被彻底重写,API 也发生了大幅度的改变。 ### TypeScript While Angular 1 could be used for smaller applications, Angular 2 has shifted focus to best facilitate large enterprise applications. As part of this, it almost requires TypeScript, which can be very useful for developers that desire the type safety of languages such as Java and C#. +虽然 Angular 1 还能用于构建一些小型应用,Angular 2 已经把注意力放在支持大型的企业级应用上。出于这个原因,Typescript 几乎变成了 Angular 2 的必需品,它对于那些渴望类型安全机制(比如 Java 和 C#)的开发者非常有用。 -Vue is also well-suited to [enterprise environments](https://github.com/vuejs/awesome-vue#enterprise-usage) and can even be used with TypeScript via our [official typings](https://github.com/vuejs/vue/tree/next/types) and [user-contributed decorators](https://github.com/itsFrank/vue-typescript), though it's definitely optional in our case. +Vue is also well-suited to [enterprise environments](https://github.com/vuejs/awesome-vue#enterprise-usage) and can even be used with TypeScript via our [official typings](https://github.com/vuejs/vue/tree/dev/types) and [user-contributed decorators](https://github.com/itsFrank/vue-typescript), though it's definitely optional in our case. +Vue 对于[企业环境](https://github.com/vuejs/awesome-vue#enterprise-usage)也十分适用,你甚至可以通过[官方的类型声明](https://github.com/vuejs/vue/tree/dev/types) 和 [用户贡献的装饰符](https://github.com/itsFrank/vue-typescript),来和 TypeScript 搭配使用。不过 TypeScript 对于 Vue 来说不是必需的。 -### Size and Performance +### 文件大小和性能 (Size and Performance) In terms of performance, both frameworks are exceptionally fast and there isn't enough data from real world use cases to make a verdict. However if you are determined to see some numbers, Vue 2.0 seems to be ahead of Angular 2 according to this [3rd party benchmark](http://stefankrause.net/js-frameworks-benchmark4/webdriver-ts/table.html). +从性能的角度,两个框架都非常快,目前我们并没有足够的数据来说明这两者之间的差异。如果你确实想看一些这方面的数据,根据这个 [第三方的测试基准](http://stefankrause.net/js-frameworks-benchmark4/webdriver-ts/table.html),Vue 2.0 好像的确胜过 Angular 2。 Size wise, although Angular 2 with offline compilation and tree-shaking is able to get its size down considerably, a full-featured Vue 2.0 with compiler included (23kb) is still lighter than a tree-shaken bare-bone example of Angular 2 (50kb). And do note the Angular 2 app's size is small due to tree-shaking, which removes code for features that you are not using. It will eventually grow back to its actual size as you import and use more features from the framework. +从文件大小的角度,虽然 Angular 2 用离线编译和 tree-shaking 可以大大降低文件大小。但一个包含了编译器的完整的 Vue 2.0 (23kb) 依然比 Angular 2 (50kb) 要小。但是要注意,Angular 2 的体积缩小是因为 tree-shaking,这意味着你没有用到的代码会被删除掉。如果你导入且使用了更多的 Angular 2 特性,它最终会变回原来的大小。 -### Flexibility +### 灵活性 (Flexibility) Vue is much less opinionated than Angular 2, offering official support for a variety of build systems, with no restrictions on how you structure your application. Many developers enjoy this freedom, while some prefer having only one Right Way to build any application. +Vue 相对 Angular 2 而言更加中立,它为不同的构建系统提供了官方支持,而且没有对你的项目结构提出任何限制。许多开发者享受这种自由度,但同时也有一些开发者喜欢“只有一种正确做法”的开发方式。 -### Learning Curve +### 学习曲线 (Learning Curve) To get started with Vue, all you need is familiarity with HTML and ES5 JavaScript (i.e. plain JavaScript). With these basic skills, you can start building non-trivial applications within less than a day of reading [the guide](/guide). +要上手 Vue,你只需要熟悉 HTML 和 ES5 (也就是普通的 JavaScript)。有了这些基本知识,花上不到一天来阅读 [教程](/guide),你就可以开始开发了。 -Angular 2's learning curve is much steeper. Even without TypeScript, their [Quickstart guide](https://angular.io/docs/js/latest/quickstart.html) starts out with an app that uses ES2015 JavaScript, NPM with 18 dependencies, 4 files, and over 3,000 words to explain it all - just to say Hello World. It's an understatement to say that [Vue's Hello World](index.html#Hello-World) is considerably simpler. It's so trivial in fact, that we don't even dedicate a whole page in the guide to it. +Angular 2's learning curve is much steeper. Even without TypeScript, their [Quickstart guide](https://angular.io/docs/js/latest/quickstart.html) starts out with an app that uses ES2015 JavaScript, NPM with 18 dependencies, 4 files, and over 3,000 words to explain it all - just to say Hello World. It's an understatement to say that [Vue's Hello World](https://jsfiddle.net/chrisvfritz/50wL7mdz/) is considerably simpler. It's so trivial in fact, that we don't even dedicate a whole page in the guide to it. +Angular 2 的学习曲线则要陡峭的多。即使是有 TypeScript 的帮助,它们的 [上手教程](https://angular.io/docs/js/latest/quickstart.html) 也还是使用了 ES2015,拥有 18 个 NPM 依赖,4个文件,以及超过 3000 个英文单词来解释,而这仅仅是为了写 Hello World 程序而已。相比之下,[Vue 的 Hello World 程序](https://jsfiddle.net/chrisvfritz/50wL7mdz/) 就超级简单,我们甚至都没有花费教程里的篇幅来介绍它。 ## Ember Ember is a full-featured framework that is designed to be highly opinionated. It provides a lot of established conventions and once you are familiar enough with them, it can make you very productive. However, it also means the learning curve is high and flexibility suffers. It's a trade-off when you try to pick between an opinionated framework and a library with a loosely coupled set of tools that work together. The latter gives you more freedom but also requires you to make more architectural decisions. +Ember 是一个全能框架,有着强烈的开发主张。它提出了很多约定,如果你对它们足够熟悉,这会让你可以非常高效地进行开发。不过,这也意味着它的学习曲线非常陡峭,而且灵活性不高。在一个具有强烈主张的框架(Ember),和一系列松散耦合的工具(Vue)之间做出选择时,你必需进行权衡。后者给你更多的自由度,但是需要自己做更多的架构上的决定。 That said, it would probably make a better comparison between Vue core and Ember's [templating](https://guides.emberjs.com/v2.7.0/templates/handlebars-basics/) and [object model](https://guides.emberjs.com/v2.7.0/object-model/) layers: +也就是说,我们最好来比较一下 Vue 的内核,以及 Ember 的 [模版](https://guides.emberjs.com/v2.7.0/templates/handlebars-basics/) 与 [对象模型](https://guides.emberjs.com/v2.7.0/object-model/) 层: - Vue provides unobtrusive reactivity on plain JavaScript objects and fully automatic computed properties. In Ember, you need to wrap everything in Ember Objects and manually declare dependencies for computed properties. +Vue 以一种自然的方式,在普通 JavaScript 对象上提供了响应式特性。而在 Ember 里面,你需要将所有东西都封装成 Ember 对象,手动声明计算属性的依赖。 -- Vue's template syntax harnesses the full power of JavaScript expressions, while Handlebars' expression and helper syntax is quite limited in comparison. +- Vue's template syntax harnesses the full power of JavaScript expressions, while Handlebars' expression and helper syntax is intentionally quite limited in comparison. +Vue 的模版语法充分利用了 JavaScript 表达式的能力,而相比之下, Hnadlebar 则有意限制表达式和 helper 语法。 - Performance-wise, Vue outperforms Ember by a fair margin, even after the latest Glimmer engine update in Ember 2.0. Vue automatically batches updates, while in Ember you need to manually manage run loops in performance-critical situations. +从性能的角度,Vue 远胜 Ember,即使在 Ember 2.0 最新的 Glimmer 引擎更新之后。Vue 会自动地批量处理更新,而在追求性能的场景下, Ember 需要你手动管理运行循环。 ## Knockout Knockout was a pioneer in the MVVM and dependency tracking spaces and its reactivity system is very similar to Vue's. Its [browser support](http://knockoutjs.com/documentation/browser-support.html) is also very impressive considering everything it does, with support back to IE6! Vue on the other hand only supports IE9+. +Knockout 是 MVVM 和依赖跟踪的先驱,它的响应式系统和 Vue 十分相似。考虑到它提供的功能,Knockout 的[浏览器支持](http://knockoutjs.com/documentation/browser-support.html) 可以说相当的出色,甚至还支持 IE6!而 Vue 则只支持 IE9+。 Over time though, Knockout development has slowed and it's begun to show its age a little. For example, its component system lacks a full set of lifecycle hooks and although it's a very common use case, the interface for passing children to a component feels a little clunky compared to [Vue's](components.html#Content-Distribution-with-Slots). +不过随着时间推移,Knockout 的开发速度已经慢了下来。比如,它的组件系统缺少一整套生命周期钩子,传递子组件的接口相对于 [Vue](components.html#Content-Distribution-with-Slots) 来说也非常笨重,即使它经常会被用到。 There also seem to be philosophical differences in the API design which if you're curious, can be demonstrated by how each handles the creation of a [simple todo list](https://gist.github.com/chrisvfritz/9e5f2d6826af00fcbace7be8f6dccb89). It's definitely somewhat subjective, but many consider Vue's API to be less complex and better structured. +在 API 设计上两者也有一些哲学上的差异,你可以在下面这个[简单 todo 列表](https://gist.github.com/chrisvfritz/9e5f2d6826af00fcbace7be8f6dccb89)的示例代码里看到这些差异。虽然有点主观,但很多人都认为 Vue 的 API 要更简单优雅。 ## Polymer Polymer is yet another Google-sponsored project and in fact was a source of inspiration for Vue as well. Vue's components can be loosely compared to Polymer's custom elements and both provide a very similar development style. The biggest difference is that Polymer is built upon the latest Web Components features and requires non-trivial polyfills to work (with degraded performance) in browsers that don't support those features natively. In contrast, Vue works without any dependencies or polyfills down to IE9. +Polymer 是另一个 Google 赞助的项目,实际上它也是 Vue 的一个灵感来源。Vue 的组件可以跟 Polymer 的自定义元素粗略类比,两者都有类似的开发风格。最大的区别在于 Polymer 是基于 Web Components 特性,在还没有支持这个特性的浏览器上,需要引入一个不小的 polyfill,降低了它的性能。相比之下,Vue 不需要任何依赖和 polyfill,就可以在 IE9+ 的浏览器上运行。 In Polymer 1.0, the team has also made its data-binding system very limited in order to compensate for the performance. For example, the only expressions supported in Polymer templates are boolean negation and single method calls. Its computed property implementation is also not very flexible. +在 Polymer 1.0中,出于性能考虑,开发团队将数据绑定系统设计得非常局限。比如,在 Polymer 模版中的表达式只支持布尔值的否操作和普通的函数调用。它对于计算属性的实现也比较死板。 Polymer custom elements are authored in HTML files, which limits you to plain JavaScript/CSS (and language features supported by today's browsers). In comparison, Vue's single file components allows you to easily use ES2015+ and any CSS preprocessors you want. +Polymer 的自定义元素是在 HTML 文件里面编写的,所以你只能用普通的 JavaScript/CSS (以及浏览器所支持的属性)。而 Vue 的单文件组件让你可以轻松地使用 ES2015+ 以及你所偏好的 CSS 预编译器。 When deploying to production, Polymer recommends loading everything on-the-fly with HTML Imports, which assumes browsers implementing the spec, and HTTP/2 support on both server and client. This may or may not be feasible depending on your target audience and deployment environment. In cases where this is not desirable, you will have to use a special tool called Vulcanizer to bundle your Polymer elements. On this front, Vue can combine its async component feature with Webpack's code-splitting feature to easily split out parts of the application bundle to be lazy-loaded. This ensures compatibility with older browsers while retaining great app loading performance. +在部署到生产环境时,Polymer 推荐你使用 HTML 导入加载所有资源,但浏览器必需支持相关的特性,而且浏览器和客户端都要支持 HTTP/2。考虑到目标用户和部署环境,有时候这是不现实的。在这种情况下,你需要用到一个叫做 Vulcanizer 的特殊工具来构建你的 Polymer 元素。而在这个问题上,Vue 可以用异步组件特性配合 Webpack 的代码分割特性,将打包的应用分块,实现懒加载。这既兼容了老式浏览器,又保证了应用加载的性能。 -It is also totally feasible to offer deeper integration between Vue with Web Component specs such as Custom Elements and Shadow DOM style encapsulation - however at this moment we are still waiting for the specs to mature and be widely implemented in all mainstream browsers before making any serious committments. +It is also totally feasible to offer deeper integration between Vue with Web Component specs such as Custom Elements and Shadow DOM style encapsulation - however at this moment we are still waiting for the specs to mature and be widely implemented in all mainstream browsers before making any serious commitments. +Vue 完全可以更深入地和 Web Component 标准融合,比如自定义元素和影子 DOM 这样的封装 - 不过我们会等到这个标准成熟,并且主流浏览器广泛实现这个标准之后,再去认真地投入精力。 ## Riot Riot 2.0 provides a similar component-based development model (which is called a "tag" in Riot), with a minimal and beautifully designed API. Riot and Vue probably share a lot in design philosophies. However, despite being a bit heavier than Riot, Vue does offer some significant advantages: +Riot 2.0 提供了一个跟 Vue 类似的基于组件的开发模型(在 Riot 中被称为 "tag"),而且它还有一个小巧优雅的 API。Riot 和 Vue 在设计思路上又很多相同的地方。虽然 Vue 比 Riot 要更重一些,但 Vue 有一些明显的优势: - True conditional rendering. Riot renders all if branches and simply shows/hides them. +Vue 提供了真正的条件渲染。而 Riot 渲染了所有的条件分支,只是将其它们选择性地显示和隐藏。 - A far more powerful router. Riot’s routing API is extremely minimal. -- More mature tooling support. Vue provides official support for [Webpack](https://github.com/vuejs/vue-loader), [Browserify](https://github.com/vuejs/vueify), and [SystemJS](https://github.com/vuejs/systemjs-plugin-vue), while Riot relies on community support for build system integration. +Vue 有一个更加强大的路由系统。Riot 的路由 API 真的是非常局限。 +- More mature tooling support. Vue provides official support for [Webpack](https://github.com/vuejs/vue-loader) and [Browserify](https://github.com/vuejs/vueify), while Riot relies on community support for build system integration. +Vue 的工具支持更加成熟。它对 [Webpack](https://github.com/vuejs/vue-loader) 和 [Browserify](https://github.com/vuejs/vueify) 提供了官方支持。而 Riot 对构建系统的支持依赖于它的社区。 - [Transition effect system](transitions.html). Riot has none. +Vue 有[过渡效果系统](transitions.html),而 Riot 还没有。 - Better performance. [Despite advertising](https://github.com/vuejs/vuejs.org/issues/346) use of a virtual DOM, Riot in fact uses dirty checking and thus suffers from the same performance issues as Angular 1. +Vue 有更好的性能。尽管 Riot [对外宣称](https://github.com/vuejs/vuejs.org/issues/346) 使用了虚拟 DOM,但它实际上还是使用了脏检查机制,所以跟 Angular 1 有着同样的性能问题。 diff --git a/src/guide/components.md b/src/guide/components.md index 29dfccc1c4..aec4ad42d1 100644 --- a/src/guide/components.md +++ b/src/guide/components.md @@ -1,37 +1,44 @@ --- -title: Components +title: 组件 (Components) type: guide order: 11 --- -## What are Components? +## 组件是什么? (What are Components?) Components are one of the most powerful features of Vue. They help you extend basic HTML elements to encapsulate reusable code. At a high level, components are custom elements that Vue's compiler attaches behavior to. In some cases, they may also appear as a native HTML element extended with the special `is` attribute. +组件是 Vue 最强大的特性之一。组件可以扩展 HTML 元素,封装可复用的代码。从更抽象的层面上讲,组件是自定义元素,而 Vue 编译器将行为绑定到组件上。在某些情况下,组件会以原生 HTML 元素的形式出现,但多了一个特殊的 `is` 属性。 -## Using Components +## 使用组件 (Using Components) -### Registration +### 注册组件 (Registration) -We've learned in the previous sections that we can create a new Vue instances with: +We've learned in the previous sections that we can create a new Vue instance with: +通过先前章节,我们知道可以这样创建一个 Vue 实例: ``` js new Vue({ el: '#some-element', // options + // 选项 }) ``` To register a global component, you can use `Vue.component(tagName, options)`. For example: +可以用 `Vue.component(tagName, options)` 注册一个全局的组件: ``` js Vue.component('my-component', { // options + // 选项 }) ``` -
Note that Vue does not enforce the [W3C rules](http://www.w3.org/TR/custom-elements/#concepts) for custom tag names (all-lowercase, must contain a hyphen) though following this convention is considered good practice.
+Note that Vue does not enforce the [W3C rules](http://www.w3.org/TR/custom-elements/#concepts) for custom tag names (all-lowercase, must contain a hyphen) though following this convention is considered good practice. +注意,Vue 并不强制要求遵循 [W3C 规则](http://www.w3.org/TR/custom-elements/#concepts) (全小写,必须包含一个短横杠) 来命名标签名,不过遵循这个规则是好的做法。
Once registered, a component can be used in an instance's template as a custom element, `