diff --git a/README.md b/README.md index 3f866306b7..088a38e5a9 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,163 @@ -# vue.js 2.0 正式版 中文翻译文档(正在进行中...) http://vuefe.cn +## vue.js 2.0 中文文档 http://vuefe.cn -> 基于 hexo && vuejs.org -> 求小伙伴共同翻译,有兴趣加qq 315129552 +>(即将完成 - 急需校对) -- 中文翻译分支 2.0-cn +## 贡献要求 -## 开发 +### 参与: -``` -$ npm install -g hexo-cli -$ npm install -$ hexo server -``` +- 加群参与 `42744737` +- [发布网址:vuefe.cn](http://vuefe.cn/) +- [翻译仓库](https://github.com/vuefe/vuejs.org),中文翻译分支 2.0-cn +- [基础指引](https://github.com/vuefe/vuejs.org/wiki/%E5%85%B3%E4%BA%8E%E7%BF%BB%E8%AF%91---%E5%9F%BA%E7%A1%80%E6%8C%87%E5%BC%95) +- 参与API翻译:https://github.com/vuefe/vuejs.org/issues/44 +- 参与Guide校对:https://github.com/vuefe/vuejs.org/issues/77 +- 提出建议:https://github.com/vuefe/vuejs.org/issues/48 +- 如果你看到错别字、漏译、错译,请直接提交 pr + ([帮助](https://help.github.com/articles/using-pull-requests/))。 +- 如果你看到网站问题,或者创建一个 issue,或者直接提交 pr。 +- 如果你对已有翻译有异议,建议创建一个 issue 讨论。 +- 如果你想修改英文内容,请去 [vuejs.org 项目][vuejs.org]。 +- 如果你想求教 Vue.js 使用问题,请去[论坛][forum]。 +- 如果你遇到 Vue.js 的问题,请去 [vue 项目][vue], + 创建 issue 并提供演示。可以在 JSBin, JSFiddle, Codepen 等网站创建演示。 + +### 翻译要求 + +- 保持一致,清晰 +- 汉字,字母,数字等之间以一个空格隔开。 +- 中文使用中文符号,英文使用英文符号。 +- 专有词注意大小写,如 HTML,CSS,JavaScript。 +- 术语与已有译文保持一致,如果有异议请先在 issue 中讨论。 +- 代码只翻译注释。 +- 标题会转化为链接,文档其它地方可能会用到,所以标题应尽量简短, + 在修改标题时搜索一下它是否还用在其它地方。 + 同样的,在修改文档内链接时也应搜索一下。 +- 校对后对应修改提交合并请求 + +### 统一固定词汇翻译 + +- Type => 类型 +- See also => 另见 +- Details => 详细 +- Options => 选项 +- Example => 示例 +- Restriction => 限制 +- default => 默认值 +- prop => 特性(是指 一个 API 时候,不要翻译成中文) +- attribute => 特性 +- transition => 过渡 + +### 术语翻译对照 -Start a dev server at `localhost:4000` +- attribute 特性 +- transition 过渡 -## merge +### 不翻译的术语 -- 翻译完 pull request 到 2.0-cn 分支 合并 +- getter +- setter +- prop(指API时) -## 发布 +### 认领说明 -> 预先添加git ssh +- 参与前,请在对应issue认领 +- 认领格式 : + - 未完成 + - [ ] 我校对 + `文档序号 ` +- markdown语法 - 示例 + +```markdown +- [ ] 我xx `1` ``` -hexo g -hexo d + + - 完成后,打钩表示完成,并附带 发起的合并请求链接 + - [x] 我校对 + `文档序号 ` + https://github.com/vuefe/vuejs.org/pull/65 (发起的合并请求链接) + +- markdown语法 - 示例 + +```markdown +- [x] 我xx + `1 ` https://github.com/vuefe/vuejs.org/pull/65 (发起的合并请求链接) ``` -## 当前说明(2016.09.26) +- 支持多人协作翻译,冲突可以解决,认领过的,如果你觉着他太慢,可以再次认领,加速翻译,知道大家都是牺牲业余时间来贡献,所以慢也是可以理解的,慢就需要大家一起帮帮忙了!谢谢。 + + +## Guide 翻译贡献 + +### Essentials 基础 + +序号 | 是否完成 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对贡献者 +----- | ------- | ------------- | --- | --- | --- | --- +1 | 是 | installation.md | 安装 | [dingyiming](https://github.com/dingyiming) | +2 | 是 | index.md | 介绍 | [hijiangtao](https://github.com/hijiangtao) | +3 | 是 | instance.md | 实例 | [dingyiming](https://github.com/dingyiming) | +4 | 是 | syntax.md | 模板语法 | [daix6](https://github.com/daix6) | +5 | 是 | computed.md | 计算属 性 | [dingyiming](https://github.com/dingyiming) | +6 | 是 | class-and-style.md | Class 与 Style 绑定 | [595074187](https://github.com/595074187) | +7 | 是 | conditional.md | 条件渲染 | [dingyiming](https://github.com/dingyiming) | +8 | 是 | list.md | 列表渲染 | [tingtien](https://github.com/tingtien) | +9 | 是 | events.md | 事件处理器 | [dingyiming](https://github.com/dingyiming) | +10 | 是 | forms.md | 表单控件绑定 | [dingyiming](https://github.com/dingyiming) | +11 | 是 | components.md | 组件 | [ezreally](https://github.com/ezreally) | + +### Advanced 进阶 + +序号 | 是否完成 | 对应文档文件名 | 中文标题 | 贡献者 | 校对贡献者 +----- | ------- | ------------- | --- | --- | --- | --- +12 | 是 | transitions.md | 过渡: 进入, 离开, 和 列表 | [awe](https://github.com/hilongjw) | +13 | 是 | transitioning-state.md | 过渡状态 | [awe](https://github.com/hilongjw) | +14 | 是 | render-function.md | Render 函数 | [awe](https://github.com/hilongjw) | +15 | 是 | reactivity.md | 深入响应式原理 | [veaba](https://github.com/veaba) | +16 | 是 | custom-directive.md | 自定义指令 | [harrytospring](https://github.com/harrytospring) | +17 | 是 | mixins.md | 混合 | [harrytospring](https://github.com/harrytospring) | +18 | 是 | plugins.md | 插件 | [hgcoder](https://github.com/hgcoder) | +19 | 是 | single-file-components.md | 单文件组件 | [ATLgo](https://github.com/ATLgo) | +20 | 是 | routing.md | 路由 | [dingyiming](https://github.com/dingyiming) | +21 | 是 | state-management.md | 状态管理 | [dear-lizhihua](https://github.com/dear-lizhihua) | +22 | 是 | unit-testing.md | 单元测试 | [70data](https://github.com/70data) | +23 | 是 | ssr.md | 服务端渲染 | [dingyiming](https://github.com/dingyiming)|  + +### Migration 迁移 + +序号 | 是否完成 | 对应文档文件名 | 中文标题 | 贡献者 | 校对贡献者 +----- | ------- | ------------- | --- | --- | --- +24 | 是 | migration.md | 1.x迁移 | [harrytospring](https://github.com/harrytospring) | +27 | 是 | migration-vue-router.md | vue-router 0.7.x 迁移 | [forzajuve10](https://github.com/forzajuve10) | + +### Meta 更多 + +序号 | 是否完成 | 对应文档文件名 | 中文标题 | 贡献者 | 校对贡献者 +----- | ------- | ------------- | --- | --- | --- +25 | 是 | comparison.md | 对比其他框架 | [yongbolv](https://github.com/yongbolv) | +26 | 是 | join.md | 加入Vue.js社区 | [daix6](https://github.com/daix6) | + + +## API翻译贡献 + +序号 | 是否完成 | 对应小节名称 | 中文标题 | 贡献者 | 校对贡献者 +----- | ------- | ------------- | --- | --- | --- +1 | 是 | Global Config | 全局配置 | @dear-lizhihua | +2 | 是 | Global API | 全局API | @dear-lizhihua | +3 | 是 | Options / Data | 选项 / 数据 | @dear-lizhihua | +4 | 是 | Options / DOM | 选项 / DOM | @ATLgo | +5 | 是 | Options / Lifecycle Hooks | 选项 / 生命周期钩子 | @ATLgo | +6 | 是 | Options / Assets | 选项 / 资源 | @dingyiming | +7 | 是 | Options / Misc | 选项 / 杂项 | @dingyiming | +8 | 是 | Instance Properties | 实例属性 | @coolzjy | +9 | 是 | Instance Methods / Data | 实例方法 / 数据 | @dingyiming | +10 | 是 | Instance Methods / Events | 实例方法 / 事件 | @mlyknown | +11 | 是 | Instance Methods / Lifecycle | 实例方法 / 生命周期 | @mlyknown | +12 | 是 | Directives | 指令| @dingyiming | +13 | 是 | Special Attributes | 特殊元素 | @70data | +14 | 是 | Built-In Components | 内置的组件 | @dear-lizhihua | +15 | 是 | VNode Interface | VNode接口 | @70data | +16 | 是 | Server-Side Rendering | 服务端渲染| @70data | + +## 示例翻译 + +贡献者 : [lindazhang102](https://github.com/lindazhang102) + -* 基于hexo 和vuejs.org源码 -* 翻译有些滞后,刚刚更新,希望有兴趣的小伙伴直接找我,共勉 -* 文段中英文字母与中文用空一格做间隔,有助于阅读 -* 请尽量对照 vuejs 官方 1.0 中文文档进行翻译,也可以即时看出vue1和vue2直接的区别 -* 导航上 添加了 更新 模块,用于链接到github的 release信息,后面希望单独把changelog放到 /changelog中跟进翻译每次的版本更新内容 -* (畅想:加入热点标记功能 - 点击热点新建github 对应 issue ,话题链接 / 增强文档交互即时纠错) -* (畅想: 首页加入弹幕交互功能) -* (畅想: 添加hacknews-vue2案例解析 以及更多自定义案例解析) +## 感谢所有参与翻译的朋友们! \ No newline at end of file diff --git a/_config.yml b/_config.yml index 7ce6c2a161..c8bb955748 100644 --- a/_config.yml +++ b/_config.yml @@ -8,7 +8,7 @@ subtitle: description: "Reactive Components for Modern Web Interfaces" author: Evan You email: -language: +language: zh-CN # URL ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' diff --git a/src/about/guide.md b/src/about/guide.md index 79d4a353b2..2a80f884a8 100644 --- a/src/about/guide.md +++ b/src/about/guide.md @@ -1,62 +1,91 @@ --- title: 参与指南 type: about -order: 2 +order: 1 --- -- 加QQ群参与翻译: `427447379` -- [翻译Guide认领](https://github.com/vuefe/vuejs.org/issues/1) -- [翻译指引](https://github.com/vuefe/vuejs.org/issues/25) - -## 翻译进度 - -> 原文地址:http://vuejs.org/guide/ -> 仓库:https://github.com/vuefe/vuejs.org - -### 说明 - -- 翻译前,请在此回复认领 -- 认领格式 :` 我翻译 + 文档序号` 即可 - -## 以下所有文档所在目录为 `src/guide/xxx.md` - -### Essentials 基础 - -序号 | 是否完成 | 对应文档文件名 | 中文标题 | 贡献者 | 认领者 ------ | ------- | ------------- | --- | --- | --- -1 | 是 | installation.md | 安装 | @dingyiming | - -2 | 否 | index.md | 介绍 | | @dingyiming -3 | 是 | instance.md | 实例 | @dingyiming | - -4 | × | syntax.md | 模板语法 | | | -5 | 是 | computed.md | 计算属性 | @dingyiming | - -6 | × | class-and-style.md | Class 与 Style 绑定 | | -7 | 是 | conditional.md | 条件渲染 | @dingyiming | - -8 | 是 | list.md | 列表渲染 | @tingtien | @tingtien -9 | 是 | events.md | 事件处理器 | @dingyiming | - -10 | 是 | forms.md | 表单控件绑定 | @dingyiming | - -11 | × | components.md | 组件 | | @ezreally - -### Advanced 进阶 - -序号 | 是否完成 | 对应文档文件名 | 中文标题 | 贡献者 | 认领者 ------ | ------- | ------------- | --- | --- | --- -12 | 是 | transitions.md | 过渡: 进入, 离开, 和 列表 | @awe | @awe -13 | 是 | transitioning-state.md | 过渡状态 | @awe | @awe -14 | 是 | render-function.md | Render 函数 | @awe | @awe -15 | x | reactivity.md | 深入响应式原理 | | @veaba -16 | 是 | custom-directive.md | 自定义指令 | @harrytospring | @harrytospring -17 | 是 | mixins.md | 混合 | @harrytospring | @harrytospring -18 | x | plugins.md | 插件 | | @hgcoder -19 | x | single-file-components.md | 单文件组件 | | -20 | 是 | routing.md | 路由 | @dingyiming | @dingyiming -21 | x | state-management.md | 状态管理 | | -22 | x | unit-testing.md | 单元测试 | | @70data -23 | 是 | ssr.md | 服务端渲染 | @dingyiming | @dingyiming -24 | x | migration.md | 1.x迁移 | | @harrytospring - -### Meta 更多 - -序号 | 是否完成 | 对应文档文件名 | 中文标题 | 贡献者 | 认领者 ------ | ------- | ------------- | --- | --- | --- -25 | x | comparison.md | 对比其他框架 | | @yongbolv @daix6 -26 | x | join.md | 加入Vue.js社区 | | @daix6 +> 目前急需校对 + + +## 参与要求 + +### 参与: + +> 参与请阅读 [翻译规范](https://github.com/vuefe/vuejs.org/wiki/%E7%BF%BB%E8%AF%91%E8%A7%84%E8%8C%83) + +- 加群参与 `42744737` +- [发布网址:vuefe.cn](http://vuefe.cn/) +- [翻译仓库](https://github.com/vuefe/vuejs.org) ,中文翻译分支 2.0-cn +- [基础指引](https://github.com/vuefe/vuejs.org/wiki/%E5%85%B3%E4%BA%8E%E7%BF%BB%E8%AF%91---%E5%9F%BA%E7%A1%80%E6%8C%87%E5%BC%95) +- 参与API翻译:https://github.com/vuefe/vuejs.org/issues/44 +- 参与Guide校对:https://github.com/vuefe/vuejs.org/issues/77 +- 提出建议:https://github.com/vuefe/vuejs.org/issues/48 +- 如果你看到错别字、漏译、错译,请直接提交 pr + ([帮助](https://help.github.com/articles/using-pull-requests/))。 +- 如果你看到网站问题,或者创建一个 issue,或者直接提交 pr。 +- 如果你对已有翻译有异议,建议创建一个 issue 讨论。 +- 如果你想修改英文内容,请去 [vuejs.org 项目][vuejs.org]。 +- 如果你想求教 Vue.js 使用问题,请去[论坛][forum]。 +- 如果你遇到 Vue.js 的问题,请去 [vue 项目][vue], + 创建 issue 并提供演示。可以在 JSBin, JSFiddle, Codepen 等网站创建演示。 + +### 翻译要求 + +- 保持一致,清晰 +- 汉字,字母,数字等之间以一个空格隔开。 +- 中文使用中文符号,英文使用英文符号。 +- 专有词注意大小写,如 HTML,CSS,JavaScript。 +- 术语与已有译文保持一致,如果有异议请先在 issue 中讨论。 +- 代码只翻译注释。 +- 标题会转化为链接,文档其它地方可能会用到,所以标题应尽量简短, + 在修改标题时搜索一下它是否还用在其它地方。 + 同样的,在修改文档内链接时也应搜索一下。 +- 校对后对应修改提交合并请求 + +### 统一固定词汇翻译 + +- Type => 类型 +- See also => 另见 +- Details => 详细 +- Options => 选项 +- Example => 示例 +- Restriction => 限制 +- default => 默认值 +- prop => 特性(是指 一个 API 时候,不要翻译成中文) +- attribute => 特性 +- transition => 过渡 + +### 术语翻译对照 + +- attribute 特性 +- transition 过渡 + +### 不翻译的术语 + +- getter +- setter +- prop(指API时) + +### 认领说明 + +- 参与前,请在对应issue认领 +- 认领格式 : + - 未完成 + - [ ] 我校对 + `文档序号 ` + +- markdown语法 - 示例 + +```markdown +- [ ] 我xx `1` +``` + + - 完成后,打钩表示完成,并附带 发起的合并请求链接 + - [x] 我校对 + `文档序号 ` + https://github.com/vuefe/vuejs.org/pull/65 (发起的合并请求链接) + +- markdown语法 - 示例 + +```markdown +- [x] 我xx + `1 ` https://github.com/vuefe/vuejs.org/pull/65 (发起的合并请求链接) +``` + +- 支持多人协作翻译,冲突可以解决,认领过的,如果你觉着他太慢,可以再次认领,加速翻译,知道大家都是牺牲业余时间来贡献,所以慢也是可以理解的,慢就需要大家一起帮帮忙了!谢谢。 diff --git a/src/about/index.md b/src/about/index.md index 83e2b741fc..b0f151f38e 100644 --- a/src/about/index.md +++ b/src/about/index.md @@ -1,8 +1,88 @@ --- -title: 关于翻译 +title: 贡献者 type: about -order: 1 +order: 0 --- -- 加QQ群参与翻译: `427447379` -- [翻译Guide认领](https://github.com/vuefe/vuejs.org/issues/1) \ No newline at end of file +## 目前任务 + +- [vue 2.0 - Guide 翻译校对 (进度 / 认领)](https://github.com/vuefe/vuejs.org/issues/77) +- [vue 2.0 - API 翻译校对 (进度 / 认领)](https://github.com/vuefe/vuejs.org/issues/119) +- [vuex 2.0 - 文档翻译 (进度 / 认领)](https://github.com/vuefe/vuejs.org/issues/124) + +## Guide 翻译贡献 + +### Essentials 基础 + +序号 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对贡献者 +----- | ------------- | --- | --- | --- | --- +1 | installation.md | 安装 | [dingyiming](https://github.com/dingyiming) | +2 | index.md | 介绍 | [hijiangtao](https://github.com/hijiangtao) | +3 | instance.md | 实例 | [dingyiming](https://github.com/dingyiming) | +4 | syntax.md | 模板语法 | [daix6](https://github.com/daix6) | +5 | computed.md | 计算属 性 | [dingyiming](https://github.com/dingyiming) | +6 | class-and-style.md | Class 与 Style 绑定 | [595074187](https://github.com/595074187) | +7 | conditional.md | 条件渲染 | [dingyiming](https://github.com/dingyiming) | +8 | list.md | 列表渲染 | [tingtien](https://github.com/tingtien) | +9 | events.md | 事件处理器 | [dingyiming](https://github.com/dingyiming) | +10 | forms.md | 表单控件绑定 | [dingyiming](https://github.com/dingyiming) | +11 | components.md | 组件 | [ezreally](https://github.com/ezreally) | + +### Advanced 进阶 + +序号 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对贡献者 +----- | ------------- | --- | --- | --- +12 | transitions.md | 过渡: 进入, 离开, 和 列表 | [awe](https://github.com/hilongjw) | +13 | transitioning-state.md | 过渡状态 | [awe](https://github.com/hilongjw) | +14 | render-function.md | Render 函数 | [awe](https://github.com/hilongjw) | +15 | reactivity.md | 深入响应式原理 | [veaba](https://github.com/veaba) | +16 | custom-directive.md | 自定义指令 | [harrytospring](https://github.com/harrytospring) | +17 | mixins.md | 混合 | [harrytospring](https://github.com/harrytospring) | +18 | plugins.md | 插件 | [hgcoder](https://github.com/hgcoder) | +19 | single-file-components.md | 单文件组件 | [ATLgo](https://github.com/ATLgo) | +20 | routing.md | 路由 | [dingyiming](https://github.com/dingyiming) | +21 | state-management.md | 状态管理 | [dear-lizhihua](https://github.com/dear-lizhihua) | +22 | unit-testing.md | 单元测试 | [70data](https://github.com/70data) | +23 | ssr.md | 服务端渲染 | [dingyiming](https://github.com/dingyiming) |   + +### Migration 迁移 + +序号 | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对贡献者 +----- | ------------- | --- | --- | --- +24 | migration.md | 1.x迁移 | [harrytospring](https://github.com/harrytospring) | +27 | migration-vue-router.md | vue-router 0.7.x 迁移 | [forzajuve10](https://github.com/forzajuve10) | + +### Meta 更多 + +序号 | | 对应文档文件名 | 中文标题 | 翻译贡献者 | 校对贡献者 +----- | ------------- | --- | --- | --- | --- +25 | comparison.md | 对比其他框架 | [yongbolv](https://github.com/yongbolv) | +26 | join.md | 加入Vue.js社区 | [daix6](https://github.com/daix6) | + +## API翻译贡献 + +序号 | 对应小节名称 | 中文标题 | 翻译贡献者 | 校对贡献者 +----- | ------------- | --- | --- | --- +1 | Global Config | 全局配置 | [dear-lizhihua](https://github.com/dear-lizhihua) | +2 | Global API | 全局API | [dear-lizhihua](https://github.com/dear-lizhihua) | +3 | Options / Data | 选项 / 数据 | [dear-lizhihua](https://github.com/dear-lizhihua) | +4 | Options / DOM | 选项 / DOM | [ATLgo](https://github.com/ATLgo) | +5 | Options / Lifecycle Hooks | 选项 / 生命周期钩子 | [ATLgo](https://github.com/ATLgo) | +6 | Options / Assets | 选项 / 资源 | [dingyiming](https://github.com/dingyiming) | +7 | Options / Misc | 选项 / 杂项 | [dingyiming](https://github.com/dingyiming) | +8 | Instance Properties | 实例属性 | [coolzjy](https://github.com/coolzjy) | +9 | Instance Methods / Data | 实例方法 / 数据 | [dingyiming](https://github.com/dingyiming) | +10 | Instance Methods / Events | 实例方法 / 事件 | [mlyknown](https://github.com/mlyknown) | +11 | Instance Methods / Lifecycle | 实例方法 / 生命周期 | [mlyknown](https://github.com/mlyknown) | +12 | Directives | 指令| [dingyiming](https://github.com/dingyiming) | +13 | Special Attributes | 特殊元素 | [70data](https://github.com/70data) | +14 | Built-In Components | 内置的组件 | [dear-lizhihua](https://github.com/dear-lizhihua) | +15 | VNode Interface | VNode接口 | [70data](https://github.com/70data) | +16 | Server-Side Rendering | 服务端渲染| [70data](https://github.com/70data)| + +## 示例翻译 + +翻译贡献者 : [lindazhang102](https://github.com/lindazhang102) + + +## 感谢所有参与翻译的朋友们! \ No newline at end of file diff --git a/src/api/index.md b/src/api/index.md index 2f6bfc908a..368bf46435 100644 --- a/src/api/index.md +++ b/src/api/index.md @@ -2,31 +2,31 @@ type: api --- -## Global Config +## 全局配置 -`Vue.config` is an object containing Vue's global configurations. You can modify its properties listed below before bootstrapping your application: +`Vue.config` is 是一个对象,包含 Vue 的全局配置。可以在启动应用之前修改下列属性: ### silent -- **Type:** `boolean` +- **类型:** `boolean` -- **Default:** `false` +- **默认值:** `false` -- **Usage:** +- **用法:** ``` js Vue.config.silent = true ``` - Suppress all Vue logs and warnings. + 取消 Vue 所有的日志与警告。 ### optionMergeStrategies -- **Type:** `{ [key: string]: Function }` +- **类型:** `{ [key: string]: Function }` -- **Default:** `{}` +- **默认值:** `{}` -- **Usage:** +- **用法:** ``` js Vue.config.optionMergeStrategies._my_option = function (parent, child, vm) { @@ -40,34 +40,34 @@ type: api // Profile.options._my_option = 2 ``` - Define custom merging strategies for options. + 自定义选项的混合策略。 - The merge strategy receives the value of that option defined on the parent and child instances as the first and second arguments, respectively. The context Vue instance is passed as the third argument. + 合并策略函数接收定义在父实例和子实例上的 option,分别作为第一个和第二个参数的值,Vue实例上下文被作为第三个参数传入。 -- **See also**: [Custom Option Merging Strategies](/guide/mixins.html#Custom-Option-Merge-Strategies) +- **参考**: [自定义选项的混合策略](/guide/mixins.html#Custom-Option-Merge-Strategies) ### devtools -- **Type:** `boolean` +- **类型:** `boolean` -- **Default:** `true` (`false` in production builds) +- **默认值:** `true` (生产版为 `false`) -- **Usage:** +- **用法:** ``` js - // make sure to set this synchronously immediately after loading Vue + // 务必在加载 Vue 之后,立即同步设置以下内容 Vue.config.devtools = true ``` - Configure whether to allow [vue-devtools](https://github.com/vuejs/vue-devtools) inspection. This option's default value is `true` in development builds and `false` in production builds. You can set it to `true` to enable inspection for production builds. + 配置是否允许 [vue-devtools](https://github.com/vuejs/vue-devtools) 检查代码。开发版本默认为 `true`,生产版本默认为 `false`。生产版本设为 `true` 可以启用检查。 ### errorHandler -- **Type:** `Function` +- **类型:** `Function` -- **Default:** Error is thrown in place +- **默认值:** 默认抛出错误 -- **Usage:** +- **用法:** ``` js Vue.config.errorHandler = function (err, vm) { @@ -75,41 +75,41 @@ type: api } ``` - Assign a handler for uncaught errors during component render and watchers. The handler gets called with the error and the Vue instance. + 指定组件的渲染和观察期间未捕获错误的处理函数。处理函数被调用时,可获取错误信息和 Vue 实例。 ### keyCodes -- **Type:** `{ [key: string]: number }` +- **类型:** `{ [key: string]: number }` -- **Default:** `{}` +- **默认值:** `{}` -- **Usage:** +- **用法:** ``` js Vue.config.keyCodes = { esc: 27 } ``` - Define custom key aliases for v-on. + 自定义 v-on 键位别名。 -## Global API +## 全局 API

Vue.extend( options )

-- **Arguments:** +- **参数:** - `{Object} options` -- **Usage:** +- **用法:** - Create a "subclass" of the base Vue constructor. The argument should be an object containing component options. + 使用基础 Vue 构造器,创建一个“子类”。参数是一个包含组件选项的对象。 - The special case to note here is the `data` option - it must be a function when used with `Vue.extend()`. + `data` 选项是特例,需要注意 - 在 `Vue.extend()` 中它必须是函数 ``` html
``` ``` js - // create constructor + // 创建构造器 var Profile = Vue.extend({ template: '

{{firstName}} {{lastName}} aka {{alias}}

', data: function () { @@ -120,82 +120,82 @@ type: api } } }) - // create an instance of Profile and mount it on an element + // 创建 Profile 实例,并挂载到一个元素上。 new Profile().$mount('#mount-point') ``` - Will result in: + 结果如下: ``` html

Walter White aka Heisenberg

``` -- **See also:** [Components](/guide/components.html) +- **参考:** [组件](/guide/components.html)

Vue.nextTick( callback, [context] )

-- **Arguments:** +- **参数:** - `{Function} callback` - `{Object} [context]` -- **Usage:** +- **用法:** - Defer the callback to be executed after the next DOM update cycle. Use it immediately after you've changed some data to wait for the DOM update. + 在下次 DOM 更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法,获取更新后的 DOM。 ``` js - // modify data + // 修改数据 vm.msg = 'Hello' - // DOM not updated yet + // DOM 还没有更新 Vue.nextTick(function () { - // DOM updated + // DOM 更新了 }) ``` -- **See also:** [Async Update Queue](/guide/reactivity.html#Async-Update-Queue) +- **参考:** [异步更新队列](/guide/reactivity.html#Async-Update-Queue)

Vue.set( object, key, value )

-- **Arguments:** +- **参数:** - `{Object} object` - `{string} key` - `{any} value` -- **Returns:** the set value. +- **返回值:** 设置的值. -- **Usage:** +- **用法:** - Set a property on an object. If the object is reactive, ensure the property is created as a reactive property and trigger view updates. This is primarily used to get around the limitation that Vue cannot detect property additions. + 设置对象的属性。如果对象是响应式的,确保属性被创建后也是响应式的,同时触发视图更新。这个方法主要用于避开 Vue 不能检测属性被添加的限制。 - **Note the object cannot be a Vue instance, or the root data object of a Vue instance.** + **注意对象不能是 Vue 实例,或者 Vue 实例的根数据对象** -- **See also:** [Reactivity in Depth](/guide/reactivity.html) +- **参考:** [深入响应式原理](/guide/reactivity.html)

Vue.delete( object, key )

-- **Arguments:** +- **参数:** - `{Object} object` - `{string} key` -- **Usage:** +- **用法:** - Delete a property on an object. If the object is reactive, ensure the deletion triggers view updates. This is primarily used to get around the limitation that Vue cannot detect property deletions, but you should rarely need to use it. + 删除对象的属性。如果对象是响应式的,确保删除更新视图的触发器。这个方法主要用于避开 Vue 不能检测到属性被删除的限制,但是你应该很少会使用它。 - **Note the object cannot be a Vue instance, or the root data object of a Vue instance.** + **注意对象不能是 Vue 实例,或者 Vue 实例的根数据对象** -- **See also:** [Reactivity in Depth](/guide/reactivity.html) +- **参考:** [深入响应式原理](/guide/reactivity.html)

Vue.directive( id, [definition] )

-- **Arguments:** +- **参数:** - `{string} id` - `{Function | Object} [definition]` -- **Usage:** +- **用法:** - Register or retrieve a global directive. + 注册或获取全局指令。 ``` js - // register + // 注册 Vue.directive('my-directive', { bind: function () {}, inserted: function () {}, @@ -204,92 +204,92 @@ type: api unbind: function () {} }) - // register (simple function directive) + // 注册(传入一个简单的指令函数) Vue.directive('my-directive', function () { - // this will be called as `bind` and `update` + // 这里将会被 `bind` 和 `update` 调用 }) - // getter, return the directive definition if registered + // getter,返回已注册的指令 var myDirective = Vue.directive('my-directive') ``` -- **See also:** [Custom Directives](/guide/custom-directive.html) +- **参考:** [自定义指令](/guide/custom-directive.html)

Vue.filter( id, [definition] )

-- **Arguments:** +- **参数:** - `{string} id` - `{Function} [definition]` -- **Usage:** +- **用法:** - Register or retrieve a global filter. + 注册或获取全局过滤器。 ``` js - // register + // 注册 Vue.filter('my-filter', function (value) { - // return processed value + // 返回处理后的值 }) - // getter, return the filter if registered + // getter,返回已注册的过滤器 var myFilter = Vue.filter('my-filter') ```

Vue.component( id, [definition] )

-- **Arguments:** +- **参数:** - `{string} id` - `{Function | Object} [definition]` -- **Usage:** +- **用法:** - Register or retrieve a global component. + 注册或获取全局组件。 ``` js - // register an extended constructor + // 注册组件,传入一个扩展过的构造器 Vue.component('my-component', Vue.extend({ /* ... */ })) - // register an options object (automatically call Vue.extend) + // 注册组件,传入一个选项对象(自动调用 Vue.extend) Vue.component('my-component', { /* ... */ }) - // retrieve a registered component (always return constructor) + // 获取注册的组件(始终返回构造器) var MyComponent = Vue.component('my-component') ``` -- **See also:** [Components](/guide/components.html) +- **参考:** [组件](/guide/components.html)

Vue.use( plugin )

-- **Arguments:** +- **参数:** - `{Object | Function} plugin` -- **Usage:** +- **用法:** - Install a Vue.js plugin. If the plugin is an Object, it must expose an `install` method. If it is a function itself, it will be treated as the install method. The install method will be called with Vue as the argument. + 安装 Vue.js 插件。如果插件是一个对象,必须提供 `install` 方法。如果插件是一个函数,它会被作为 install 方法。install 方法将被作为 Vue 的参数调用。 - When this method is called on the same plugin multiple times, the plugin will be installed only once. + 当 install 方法被同一个插件多次调用,插件将只会被安装一次。 -- **See also:** [Plugins](/guide/plugins.html) +- **参考:** [插件](/guide/plugins.html)

Vue.mixin( mixin )

-- **Arguments:** +- **参数:** - `{Object} mixin` -- **Usage:** +- **用法:** - Apply a mixin globally, which affects every Vue instance created afterwards. This can be used by plugin authors to inject custom behavior into components. **Not recommended in application code**. + 全局注册一个混合,影响注册之后所有创建的每个 Vue 实例。插件作者可以使用混合,向组件注入自定义逻辑。**不推荐在应用代码中使用**。 -- **See also:** [Global Mixins](/guide/mixins.html#Global-Mixin) +- **参考:** [全局混合](/guide/mixins.html#Global-Mixin)

Vue.compile( template )

-- **Arguments:** +- **参数:** - `{string} template` -- **Usage:** +- **用法:** - Compiles a template string into a render function. **Only available in the standalone build.** + 在render函数中编译模板字符串。**只在独立构建时有效** ``` js var res = Vue.compile('
{{ msg }}
') @@ -303,43 +303,44 @@ type: api }) ``` -- **See also:** [Render Functions](/guide/render-function.html) +- **参考:** [Render 函数](/guide/render-function.html) -## Options / Data +## 选项 / 数据 ### data -- **Type:** `Object | Function` -- **Restriction:** Only accepts `Function` when used in a component definition. +- **类型:** `Object | Function` -- **Details:** +- **限制:** 组件中定义 data 只接受 `函数`。 - The data object for the Vue instance. Vue will recursively convert its properties into getter/setters to make it "reactive". **The object must be plain**: native objects such as browser API objects and prototype properties are ignored. A rule of thumb is that data should just be data - it is not recommended to observe objects with its own stateful behavior. +- **详细:** - Once observed, you can no longer add reactive properties to the root data object. It is therefore recommended to declare all root-level reactive properties upfront, before creating the instance. + Vue 实例的数据对象。Vue 将会递归将 data 的属性转换为 getter/setter,从而让 data 的属性能够响应数据变化。**对象必须是普通对象**:浏览器 API 创建的原生对象,原型上的属性会被忽略。大概来说,data 应该只能是数据 - 不推荐观察拥有状态行为的对象。 - After the instance is created, the original data object can be accessed as `vm.$data`. The Vue instance also proxies all the properties found on the data object, so `vm.a` will be equivalent to `vm.$data.a`. + 一旦观察过,不需要再次在数据对象上添加响应式属性。因此推荐在创建实例之前,就声明所有的根级响应式属性。 - Properties that start with `_` or `$` will **not** be proxied on the Vue instance because they may conflict with Vue's internal properties and API methods. You will have to access them as `vm.$data._property`. + 实例创建之后,可以通过 `vm.$data` 访问原始数据对象。Vue 实例也代理了 data 对象上所有的属性,因此访问 `vm.a` 等价于访问 `vm.$data.a`。 - When defining a **component**, `data` must be declared as a function that returns the initial data object, because there will be many instances created using the same definition. If we still use a plain object for `data`, that same object will be **shared by reference** across all instances created! By providing a `data` function, every time a new instance is created, we can simply call it to return a fresh copy of the initial data. + 以 `_` 或 `$` 开头的属性 **不会** 被 Vue 实例代理,因为它们可能和 Vue 内置的属性、 API 方法冲突。你可以使用例如 `vm.$data._property` 的方式访问这些属性。 - If required, a deep clone of the original object can be obtained by passing `vm.$data` through `JSON.parse(JSON.stringify(...))`. + 当一个组件被定义, `data` 必须声明为返回一个初始数据对象的函数,因为组件可能被用来创建多个实例。如果 `data` 仍然是一个普通对象,则所有的实例将**共享引用**同一个数据对象!通过提供 `data` 函数,每次创建一个新实例后,我们能够调用 `data` 函数,从而返回初始数据的一个全新副本数据对象。 -- **Example:** + 可以通过将 `vm.$data` 传入 `JSON.parse(JSON.stringify(...))` 得到原始数据对象。 + +- **示例:** ``` js var data = { a: 1 } - // direct instance creation + // 直接创建一个实例 var vm = new Vue({ data: data }) vm.a // -> 1 vm.$data === data // -> true - // must use function when in Vue.extend() + // Vue.extend() 中 data 必须是函数 var Component = Vue.extend({ data: function () { return { a: 1 } @@ -347,32 +348,32 @@ type: api }) ``` -

Note that __you should not use an arrow function with the `data` property__ (e.g. `data: () => { return { a: this.myProp }}`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.myProp` will be undefined.

+

注意,__不应该对 `data` 属性使用箭头函数__ (例如`data: () => { return { a: this.myProp }}`)。理由是箭头函数绑定了父级作用域的上下文,所以 this 将不会按照期望指向 Vue 实例,`this.myProp` 将是 undefined。

-- **See also:** [Reactivity in Depth](/guide/reactivity.html) +- **另见:** [深入响应式原理](/guide/reactivity.html) ### props -- **Type:** `Array | Object` +- **类型:** `Array | Object` -- **Details:** +- **详细:** - A list/hash of attributes that are exposed to accept data from the parent component. It has a simple Array-based syntax and an alternative Object-based syntax that allows advanced configurations such as type checking, custom validation and default values. + props 可以是数组或对象,用于接收来自父组件的数据。props 可以是简单的数组,或者使用对象作为替代,对象允许配置高级选项,如类型检测、自定义校验和设置默认值。 -- **Example:** +- **示例:** ``` js - // simple syntax + // 简单语法 Vue.component('props-demo-simple', { props: ['size', 'myMessage'] }) - // object syntax with validation + // 对象语法,提供校验 Vue.component('props-demo-advanced', { props: { - // just type check + // 只检测类型 height: Number, - // type check plus other validations + // 检测类型 + 其他验证 age: { type: Number, default: 0, @@ -385,19 +386,19 @@ type: api }) ``` -- **See also:** [Props](/guide/components.html#Props) +- **另见:** [Props](/guide/components.html#Props) ### propsData -- **Type:** `{ [key: string]: any }` +- **类型:** `{ [key: string]: any }` -- **Restriction:** only respected in instance creation via `new`. +- **限制:** 只用于 `new` 创建的实例中。 -- **Details:** +- **详细:** - Pass props to an instance during its creation. This is primarily intended to make unit testing easier. + 创建实例时传递 props。主要作用是方便测试。 -- **Example:** +- **示例:** ``` js var Comp = Vue.extend({ @@ -411,30 +412,31 @@ type: api } }) ``` +- **另见:** [Props](/guide/components.html#Props) ### computed -- **Type:** `{ [key: string]: Function | { get: Function, set: Function } }` +- **类型:** `{ [key: string]: Function | { get: Function, set: Function } }` -- **Details:** +- **详细:** - Computed properties to be mixed into the Vue instance. All getters and setters have their `this` context automatically bound to the Vue instance. + 计算属性将被混入到 Vue 实例中。getter 和 setter 的 this 上下文自动地绑定为 Vue 实例。 -

Note that __you should not use an arrow function to define a computed property__ (e.g. `aDouble: () => this.a * 2`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.a` will be undefined.

+

注意,__不应该使用箭头函数来定义计算属性函数__ (例如 `aDouble: () => this.a * 2`)。理由是箭头函数绑定了父级作用域的上下文,所以 `this` 将不会按照期望指向 Vue 实例,`this.a` 将是 undefined。

- Computed properties are cached, and only re-computed on reactive dependency changes. + 计算属性的结果会被缓存,除非依赖的响应式属性变化才会重新计算。 -- **Example:** +- **示例:** ```js var vm = new Vue({ data: { a: 1 }, computed: { - // get only, just need a function + // 仅读取,值只须为函数 aDouble: function () { return this.a * 2 }, - // both get and set + // 读取和设置 aPlus: { get: function () { return this.a + 1 @@ -451,20 +453,20 @@ type: api vm.aDouble // -> 4 ``` -- **See also:** - - [Computed Properties](/guide/computed.html) +- **另见:** + - [计算属性](/guide/computed.html) ### methods -- **Type:** `{ [key: string]: Function }` +- **类型:** `{ [key: string]: Function }` -- **Details:** +- **详细:** - Methods to be mixed into the Vue instance. You can access these methods directly on the VM instance, or use them in directive expressions. All methods will have their `this` context automatically bound to the Vue instance. + methods 将被混入到 Vue 实例中。可以直接通过 VM 实例访问这些方法,或者在指令表达式中使用。方法中的 `this` 自动绑定为 Vue 实例。 -

Note that __you should not use an arrow function to define a method__ (e.g. `plus: () => this.a++`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.a` will be undefined.

+

注意,__不应该使用箭头函数来定义 method 函数__ (例如 `plus: () => this.a++`)。理由是箭头函数绑定了父级作用域的上下文,所以 `this` 将不会按照期望指向 Vue 实例,`this.a` 将是 undefined。

-- **Example:** +- **示例:** ```js var vm = new Vue({ @@ -479,17 +481,17 @@ type: api vm.a // 2 ``` -- **See also:** [Methods and Event Handling](/guide/events.html) +- **另见:** [方法与事件处理器](/guide/events.html) ### watch -- **Type:** `{ [key: string]: string | Function | Object }` +- **类型:** `{ [key: string]: string | Function | Object }` -- **Details:** +- **详细:** - An object where keys are expressions to watch and values are the corresponding callbacks. The value can also be a string of a method name, or an Object that contains additional options. The Vue instance will call `$watch()` for each entry in the object at instantiation. + 一个对象,键是需要观察的表达式,值是对应回调函数。值也可以是方法名,或者包含选项的对象。Vue 实例将会在实例化时调用 `$watch()`,遍历 watch 对象的每一个属性。 -- **Example:** +- **示例:** ``` js var vm = new Vue({ @@ -502,9 +504,9 @@ type: api a: function (val, oldVal) { console.log('new: %s, old: %s', val, oldVal) }, - // string method name + // 方法名 b: 'someMethod', - // deep watcher + // 深度 watcher c: { handler: function (val, oldVal) { /* ... */ }, deep: true @@ -514,9 +516,9 @@ type: api vm.a = 2 // -> new: 2, old: 1 ``` -

Note that __you should not use an arrow function to define a watcher__ (e.g. `searchQuery: newValue => this.updateAutocomplete(newValue)`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.updateAutocomplete` will be undefined.

+

注意,__不应该使用箭头函数来定义 watcher 函数__ (例如 `searchQuery: newValue => this.updateAutocomplete(newValue)`)。理由是箭头函数绑定了父级作用域的上下文,所以 `this` 将不会按照期望指向 Vue 实例,`this.updateAutocomplete` 将是 undefined。

-- **See also:** [Instance Methods - vm.$watch](#vm-watch) +- **另见:** [实例方法 - vm.$watch](#vm-watch) ## 选项 / DOM @@ -695,65 +697,64 @@ type: api - **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram) -## Options / Assets +## 选项 / 资源 ### directives -- **Type:** `Object` +- **类型:** `Object` -- **Details:** +- **详细:** - A hash of directives to be made available to the Vue instance. +一个 用于 Vue 实例 的带 hash 的指令。 -- **See also:** - - [Custom Directives](/guide/custom-directive.html) - - [Assets Naming Convention](/guide/components.html#Assets-Naming-Convention) +- **另见:** + - [自定义指令](/guide/custom-directive.html) + - [资源命名约定](/guide/components.html#Assets-Naming-Convention) ### filters -- **Type:** `Object` +- **类型:** `Object` -- **Details:** +- **详细:** - A hash of filters to be made available to the Vue instance. +一个 用于 Vue 实例 的带 hash 的过滤器。 -- **See also:** +- **另见:** - [`Vue.filter`](#Vue-filter) ### components -- **Type:** `Object` +- **类型:** `Object` -- **Details:** +- **详细:** - A hash of components to be made available to the Vue instance. +一个 用于 Vue 实例 的带 hash 的组件。 -- **See also:** - - [Components](/guide/components.html) +- **另见:** + - [组件](/guide/components.html) -## Options / Misc +## 选项 / 杂项 ### parent -- **Type:** `Vue instance` +- **类型:** `Vue instance` -- **Details:** +- **详细:** - Specify the parent instance for the instance to be created. Establishes a parent-child relationship between the two. The parent will be accessible as `this.$parent` for the child, and the child will be pushed into the parent's `$children` array. + 指定实例的父实例,在两者之间建立父子关系。子实例可以用 `this.$parent` 访问父实例,子实例被推入父实例的 `$children` 数组中。 -

Use `$parent` and `$children` sparringly - they mostly serve as an escape-hatch. Prefer using props and events for parent-child communication.

+

同时使用 `$parent` 和 `$children` 有冲突 - 他们作为同一个入口 。更推荐用 props 和 events 实现父子组件通信

### mixins -- **Type:** `Array` - -- **Details:** +- **类型:** `Array` - The `mixins` option accepts an array of mixin objects. These mixin objects can contain instance options just like normal instance objects, and they will be merged against the eventual options using the same option merging logic in `Vue.extend()`. e.g. If your mixin contains a created hook and the component itself also has one, both functions will be called. +- **详细:** + + `mixins` 选项接受一个数组作为混合对象。这些混合实例对象可以像正常的实例对象一样包含选项,他们将在 `Vue.extend()` 里最终选择使用相同的选项合并逻辑合并。如:如果你混合包含一个钩子而创建组件本身也有一个,两个函数将被调用。 + Mixin钩子提供他们被调用的顺序,在调用组件的自己的钩子之前被调用。 - Mixin hooks are called in the order they are provided, and called before the component's own hooks. - -- **Example:** +- **示例:** ``` js var mixin = { @@ -767,36 +768,37 @@ type: api // -> 2 ``` -- **See also:** [Mixins](/guide/mixins.html) +- **另见:** [混合](/guide/mixins.html) ### name -- **Type:** `string` - -- **Restriction:** only respected when used as a component option. +- **类型:** `string` -- **Details:** +- **限制:** 只有作为组件选项时起作用。 - Allow the component to recursively invoke itself in its template. Note that when a component is registered globally with `Vue.component()`, the global ID is automatically set as its name. +- **详细:** - Another benefit of specifying a `name` option is debugging. Named components result in more helpful warning messages. Also, when inspecting an app in the Vue devtool, unnamed components will show up as ``, which isn't very informative. By providing the `name` option, you will get a much more informative component tree. + 允许组件模板递归地调用自身。注意,组件在全局用 `Vue.component()` 注册时,全局 ID 自动作为组件的 name。 + + 指定一个 `name` 选项的另一个好处是便于调试。被命名的组件有更友好的警告信息。另外,当在有 [vue-devtools](https://github.com/vuejs/vue-devtools), 未命名组件将显示成 ``, 这很没有语义。通过提供 `name` 选项,可以获得更有语义信息的组件树。 ### extends -- **Type:** `Object | Function` +- **类型:** `Object | Function` -- **Details:** +- **详细:** - Allows declaratively extending another component (could be either a plain options object or a constructor) without having to use `Vue.extend`. This is primarily intended to make it easier to extend between single file components. + + 允许声明扩展另一个组件(可以是一个简单的选择对象或构造函数),而无需使用 `Vue.extend`。这主要是为了便于扩展单文件组件。 - This is similar to `mixins`, the difference being that the component's own options takes higher priority than the source component being extended. + 这和 `mixins` 类似,区别在于,组件的选项需要比源组件被扩展有更高的优先级。 -- **Example:** +- **示例:** ``` js var CompA = { ... } - // extend CompA without having to call Vue.extend on either + // 在没有调用 Vue.extend 时候继承 CompA var CompB = { extends: CompA, ... @@ -805,65 +807,66 @@ type: api ### delimiters -- **Type:** `Array` +- **类型:** `Array` -- **default:** `["{{", "}}"]` +- **默认值:** `["{{", "}}"]` -- **Details:** +- **详细:** - Change the plain text interpolation delimiters. **This option is only available in the standalone build.** + 改变纯文本插入分隔符。 **这个选择只有在独立构建时才有用。** -- **Example:** + +- **示例:** ``` js new Vue({ delimiters: ['${', '}'] }) - // Delimiters changed to ES6 template string style + // Delimiters 将 ES6 模板转换成字符串样式 ``` ### functional -- **Type:** `boolean` +- **类型:** `boolean` -- **Details:** +- **详细:** - Causes a component to be stateless (no `data`) and instanceless (no `this` context). They are simply a `render` function that returns virtual nodes making them much cheaper to render. + 使组件无状态(没有 `data` )和无实例(没有 `this` 上下文)。他们用一个简单的 `render` 函数返回虚拟节点使他们更容易渲染。 -- **See also:** [Functional Components](/guide/render-function.html#Functional-Components) +- **另见:** [函数式组件](/guide/render-function.html#Functional-Components) -## Instance Properties +## 实例属性 ### vm.$data -- **Type:** `Object` +- **类型:** `Object` -- **Details:** +- **详细:** - The data object that the Vue instance is observing. The Vue instance proxies access to the properties on its data object. + Vue 实例观察的数据对象。Vue 实例代理了对其 data 对象属性的访问。 -- **See also:** [Options - data](#data) +- **另见:** [选项 - data](#data) ### vm.$el -- **Type:** `HTMLElement` +- **类型:** `HTMLElement` -- **Read only** +- **只读** -- **Details:** +- **详细:** - The root DOM element that the Vue instance is managing. + Vue 实例使用的根 DOM 元素。 ### vm.$options -- **Type:** `Object` +- **类型:** `Object` -- **Read only** +- **只读** -- **Details:** +- **详细:** - The instantiation options used for the current Vue instance. This is useful when you want to include custom properties in the options: + 用于当前 Vue 实例的初始化选项。当选项中需要自定义属性时会有用处: ``` js new Vue({ @@ -876,47 +879,47 @@ type: api ### vm.$parent -- **Type:** `Vue instance` +- **类型:** `Vue instance` -- **Read only** +- **只读** -- **Details:** +- **详细:** - The parent instance, if the current instance has one. + 父实例,如果当前实例有的话。 ### vm.$root -- **Type:** `Vue instance` +- **类型:** `Vue instance` -- **Read only** +- **只读** -- **Details:** +- **详细:** - The root Vue instance of the current component tree. If the current instance has no parents this value will be itself. + 当前组件树的根 Vue 实例。如果当前实例没有父实例,属性值将会是其自身。 ### vm.$children -- **Type:** `Array` +- **类型:** `Array` -- **Read only** +- **只读** -- **Details:** +- **详细:** - The direct child components of the current instance. **Note there's no order guarantee for `$children`, and it is not reactive.** If you find yourself trying to use `$children` for data binding, consider using an Array and `v-for` to generate child components, and use the Array as the source of truth. + 当前实例的直接子组件。**需要注意 `$children` 并不保证顺序,也不是响应式的。**如果你发现自己正在尝试使用 `$children` 来进行数据绑定,考虑使用一个数组配合 `v-for` 来生成子组件,并且使用 Array 作为真正的来源。 ### vm.$slots -- **Type:** `Object` +- **类型:** `Object` -- **Read only** +- **只读** -- **Details:** +- **详细:** - Used to access content [distributed by slots](/guide/components.html#Content-Distribution-with-Slots). Each [named slot](/guide/components.html#Named-Slots) has its own corresponding property (e.g. the contents of `slot="foo"` will be found at `vm.$slots.foo`). The `default` property contains any nodes not included in a named slot. + 用来访问被 [slot 分发](/guide/components.html#Content-Distribution-with-Slots)的内容。每个[具名 slot](/guide/components.html#Named-Slots) 有其响应的属性(例如:`slot="foo"` 中的内容将会在 `vm.$slots.foo` 中被找到)。`default` 属性包括了所有没有被包含在一个具名 slot 中的节点。 - Accessing `vm.$slots` is most useful when writing a component with a [render function](/guide/render-function.html). + 在使用 [render 函数](/guide/render-function.html)书写一个组件时,访问 `vm.$slots` 最有帮助。 -- **Example:** +- **示例:** ```html @@ -949,91 +952,91 @@ type: api }) ``` -- **See also:** - - [`` Component](#slot) - - [Content Distribution with Slots](/guide/components.html#Content-Distribution-with-Slots) - - [Render Functions](/guide/render-function.html) +- **另见:** + - [`` 组件](#slot) + - [使用 Slots 进行内容分发](/guide/components.html#Content-Distribution-with-Slots) + - [Render 函数](/guide/render-function.html) ### vm.$refs -- **Type:** `Object` +- **类型:** `Object` -- **Read only** +- **只读** -- **Details:** +- **详细:** - An object that holds child components that have `ref` registered. + 一个对象,其中包含了所有拥有 `ref` 注册的子组件。 -- **See also:** - - [Child Component Refs](/guide/components.html#Child-Component-Refs) +- **另见:** + - [子组件引用](/guide/components.html#Child-Component-Refs) - [ref](#ref) ### vm.$isServer -- **Type:** `boolean` +- **类型:** `boolean` -- **Read only** +- **只读** -- **Details:** +- **详细:** - Whether the current Vue instance is running on the server. + 当前 Vue 实例是否运行于服务器。 -- **See also:** [Server-Side Rendering](/guide/ssr.html) +- **另见:** [服务端渲染](/guide/ssr.html) -## Instance Methods / Data +## 实例方法 / 数据

vm.$watch( expOrFn, callback, [options] )

-- **Arguments:** +- **参数:** - `{string | Function} expOrFn` - `{Function} callback` - `{Object} [options]` - `{boolean} deep` - `{boolean} immediate` -- **Returns:** `{Function} unwatch` +- **返回值:** `{Function} unwatch` -- **Usage:** +- **用法:** - Watch an expression or a computed function on the Vue instance for changes. The callback gets called with the new value and the old value. The expression can be a single keypath or any valid binding expressions. + 观察 Vue 实例的一个表达式或计算函数。回调的参数为新值和旧值。表达式可以是某个键路径或任意合法绑定表达式。 -

Note: when mutating (rather than replacing) an Object or an Array, the old value will be the same as new value because they reference the same Object/Array. Vue doesn't keep a copy of the pre-mutate value.

+

注意:在修改(不是替换)对象或数组时,旧值将与新值相同,因为它们索引同一个对象/数组。Vue 不会保留修改之前值的副本。

-- **Example:** +- **示例:** ``` js - // keypath + // 键路径 vm.$watch('a.b.c', function (newVal, oldVal) { - // do something + // 做点什么 }) - // expression + // 表达式 vm.$watch('a + b', function (newVal, oldVal) { - // do something + // 做点什么 }) - // function + // 函数 vm.$watch( function () { return this.a + this.b }, function (newVal, oldVal) { - // do something + // 做点什么 } ) ``` - `vm.$watch` returns an unwatch function that stops firing the callback: + `vm.$watch` 返回一个取消观察函数,用来停止触发回调: ``` js var unwatch = vm.$watch('a', cb) - // later, teardown the watcher + // 之后取消观察 unwatch() ``` -- **Option: deep** +- **选项:deep** - To also detect nested value changes inside Objects, you need to pass in `deep: true` in the options argument. Note that you don't need to do so to listen for Array mutations. + 为了发现对象内部值的变化,可以在选项参数中指定 `deep: true` 。注意监听数组的变动不需要这么做。 ``` js vm.$watch('someObject', callback, { @@ -1043,57 +1046,57 @@ type: api // callback is fired ``` -- **Option: immediate** +- **选项:immediate** - Passing in `immediate: true` in the option will trigger the callback immediately with the current value of the expression: + 在选项参数中指定 `immediate: true` 将立即以表达式的当前值触发回调: ``` js vm.$watch('a', callback, { immediate: true }) - // callback is fired immediately with current value of `a` + // 立即以 `a` 的当前值触发回调 ```

vm.$set( object, key, value )

-- **Arguments:** +- **参数:** - `{Object} object` - `{string} key` - `{any} value` -- **Returns:** the set value. +- **返回值:** 设置的值. -- **Usage:** +- **用法:** - This is the **alias** of the global `Vue.set`. + 这是全局 `Vue.set` 的**别名**。 -- **See also:** [Vue.set](#Vue-set) +- **另见:** [Vue.set](#Vue-set)

vm.$delete( object, key )

-- **Arguments:** +- **参数:** - `{Object} object` - `{string} key` -- **Usage:** +- **用法:** - This is the **alias** of the global `Vue.delete`. + 这是全局 `Vue.delete` 的**别名**。 -- **See also:** [Vue.delete](#Vue-delete) +- **另见:** [Vue.delete](#Vue-delete) -## Instance Methods / Events +## 实例方法/事件

vm.$on( event, callback )

-- **Arguments:** +- **参数:** - `{string} event` - `{Function} callback` -- **Usage:** +- **用法:** - Listen for a custom event on the current vm. Events can be triggered by `vm.$emit`. The callback will receive all the additional arguments passed into these event-triggering methods. + 监听当前实例上的自定义事件。事件可以由vm.$emit触发。传入这些方法的附加参数都会传入这个方法的回调。 -- **Example:** +- **示例:** ``` js vm.$on('test', function (msg) { @@ -1105,94 +1108,94 @@ type: api

vm.$once( event, callback )

-- **Arguments:** +- **参数:** - `{string} event` - `{Function} callback` -- **Usage:** +- **用法:** - Listen for a custom event, but only once. The listener will be removed once it triggers for the first time. + 监听一个自定义事件,但是只触发一次,在第一次触发之后删除监听器。

vm.$off( [event, callback] )

-- **Arguments:** +- **参数:** - `{string} [event]` - `{Function} [callback]` -- **Usage:** +- **用法:** - Remove event listener(s). + 删除事件监听器。 - - If no arguments are provided, remove all event listeners; + - 如果没有参数,则删除所有的事件监听器; - - If only the event is provided, remove all listeners for that event; + - 如果只提供了事件,则删除这个事件所有的监听器; - - If both event and callback are given, remove the listener for that specific callback only. + - 如果同时提供了事件与回调,则只删除这个回调。

vm.$emit( event, [...args] )

-- **Arguments:** +- **参数:** - `{string} event` - `[...args]` - Trigger an event on the current instance. Any additional arguments will be passed into the listener's callback function. + 触发当前实例上的事件。附加参数都会传给监听器回调。 -## Instance Methods / Lifecycle +## 实例方法 / 生命周期

vm.$mount( [elementOrSelector] )

-- **Arguments:** +- **参数:** - `{Element | string} [elementOrSelector]` - `{boolean} [hydrating]` -- **Returns:** `vm` - the instance itself +- **返回值:** `vm` - 实例自身 -- **Usage:** +- **用法:** - If a Vue instance didn't receive the `el` option at instantiation, it will be in "unmounted" state, without an associated DOM element. `vm.$mount()` can be used to manually start the mounting of an unmounted Vue instance. + 如果 Vue 实例在实例化时没有收到 el 选项,则它处于“未挂载”状态,没有关联的 DOM 元素或片断。可以使用 `vm.$mount()` 手动地挂载一个未挂载的实例。 - If `elementOrSelector` argument is not provided, the template will be rendered as an off-document element, and you will have to use native DOM API to insert it into the document yourself. + 如果没有 `elementOrSelector` 参数,模板将被渲染为文档之外的的元素,并且你必须使用原生DOM API把它插入文档中。 - The method returns the instance itself so you can chain other instance methods after it. + 这个方法返回实例自身,因而可以链式调用其它实例方法。 -- **Example:** +- **示例:** ``` js var MyComponent = Vue.extend({ template: '
Hello!
' }) - // create and mount to #app (will replace #app) + // 创建并挂载到 #app (会替换 #app) new MyComponent().$mount('#app') - // the above is the same as: + // 同上 new MyComponent({ el: '#app' }) - // or, render off-document and append afterwards: + // 或者,在文档之外渲染并且随后挂载 var component = new MyComponent().$mount() document.getElementById('app').appendChild(vm.$el) ``` -- **See also:** - - [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram) - - [Server-Side Rendering](/guide/ssr.html) +- **另见:** + - [生命周期图示](/guide/instance.html#Lifecycle-Diagram) + - [服务端渲染](/guide/ssr.html)

vm.$forceUpdate()

-- **Usage:** +- **示例:** - Force the Vue instance to re-render. Note it does not affect all child components, only the instance itself and child components with inserted slot content. + 迫使Vue实例重修渲染。注意它仅仅影响实例本身和插入插槽内容的子组件,而不是所有子组件。

vm.$nextTick( callback )

-- **Arguments:** +- **参数:** - `{Function} callback` -- **Usage:** +- **用法:** - Defer the callback to be executed after the next DOM update cycle. Use it immediately after you've changed some data to wait for the DOM update. This is the same as the global `Vue.nextTick`, except that the callback's `this` context is automatically bound to the instance calling this method. + 将回调延迟到下次 DOM 更新循环之后执行。在修改数据之后立即使用它,然后等待 DOM 更新。它跟全局方法 Vue.nextTick 一样,不同的是回调的 this 自动绑定到调用它的实例上。 -- **Example:** +- **示例:** ``` js new Vue({ @@ -1200,12 +1203,12 @@ type: api methods: { // ... example: function () { - // modify data + // 修改数据 this.message = 'changed' - // DOM is not updated yet + // DOM 还没有更新 this.$nextTick(function () { - // DOM is now updated - // `this` is bound to the current instance + // DOM 现在更新了 + // `this` 绑定到当前实例 this.doSomethingElse() }) } @@ -1213,92 +1216,93 @@ type: api }) ``` -- **See also:** +- **另见:** - [Vue.nextTick](#Vue-nextTick) - - [Async Update Queue](/guide/reactivity.html#Async-Update-Queue) + - [异步更新队列](/guide/reactivity.html#Async-Update-Queue)

vm.$destroy()

-- **Usage:** +- **用法:** - Completely destroy a vm. Clean up its connections with other existing vms, unbind all its directives, turn off all event listeners. + 完全销毁一个实例。清理它与其它实例的连接,解绑它的全部指令及事件监听器。 - Triggers the `beforeDestroy` and `destroyed` hooks. + 在 `beforeDestroy` 和 `destroyed` 之间触发。 -

In normal use cases you shouldn't have to call this method yourself. Prefer controlling the lifecycle of child components in a data-driven fashion using `v-if` and `v-for`.

+

在大多数场景中你不应该调用这个方法。最好使用 `v-if` 和 `v-for` 指令以数据驱动的方式控制子组件的生命周期。

-- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram) +- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram) -## Directives +## 指令 ### v-text -- **Expects:** `string` +- **类型:** `string` -- **Details:** +- **详细:** - Updates the element's `textContent`. If you need to update the part of `textContent`, you should use `{% raw %}{{ Mustache }}{% endraw %}` interpolations. + 更新元素的 `textContent`。如果要更新 `textContent` 部分,需要使用 `{% raw %}{{ Mustache }}{% endraw %}` 插值。 -- **Example:** +- **示例:** ```html - + {{msg}} ``` -- **See also:** [Data Binding Syntax - interpolations](/guide/syntax.html#Text) +- **另见:** [数据绑定语法 - 插值](/guide/syntax.html#Text) ### v-html -- **Expects:** `string` +- **类型:** `string` -- **Details:** +- **详细:** - Updates the element's `innerHTML`. **Note that the contents are inserted as plain HTML - they will not be compiled as Vue templates**. If you find yourself trying to compose templates using `v-html`, try to rethink the solution by using components instead. -

Dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). Only use `v-html` on trusted content and **never** on user-provided content.

+ 更新元素的 `innerHTML` 。**注意:内容按普通 HTML 插入 - 不会作为 Vue 模板进行编译** 。如果试图使用 `v-html` 组合模板,可以重新思考通过是否通过使用组件来替代。 -- **Example:** +

在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。只在可信内容上使用 `v-html`,**永不**用在用户提交的内容上。

+ +- **示例:** ```html
``` -- **See also:** [Data Binding Syntax - interpolations](/guide/syntax.html#Raw-HTML) +- **另见** [数据绑定语法 - 插值](/guide/syntax.html#Raw-HTML) ### v-if -- **Expects:** `any` +- **类型:** `any` -- **Usage:** +- **用法:** - Conditionally render the element based on the truthy-ness of the expression value. The element and its contained directives / components are destroyed and re-constructed during toggles. If the element is a `