From 9057ce4fcc30f11f2483e848860303732e4e82fc Mon Sep 17 00:00:00 2001 From: sqrtthree Date: Fri, 23 Jun 2017 15:05:03 +0800 Subject: [PATCH 01/30] :ok_hand: Sync to keep it up-to-date with the upstream repository - Update translation due to upstream changes. - Adjust the link for tracking changes to better show differences. --- README-CN.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README-CN.md b/README-CN.md index 1e36851..518e10e 100644 --- a/README-CN.md +++ b/README-CN.md @@ -1,6 +1,6 @@ # Vue.js 组件编码规范 -> 这个 [链接](https://github.com/pablohpsilva/vuejs-component-style-guide/compare/6c5831912f9926a447f4d4531e745d53609aeb33...pablohpsilva:master) 用来查看本翻译与英文版是否有差别(如果你没有看到 README.md 发生变化,那就意味着这份翻译文档是最新的)。 +> 这个 [链接](https://github.com/sqrthree/vuejs-component-style-guide/compare/master...pablohpsilva:master) 用来查看本翻译与英文版是否有差别(如果你没有看到 README.md 发生变化,那就意味着这份翻译文档是最新的)。

@@ -28,7 +28,6 @@ * [基于模块开发](#基于模块开发) * [vue 组件命名](#vue-组件命名) - * [组件表达式简单化](#组件表达式简单化) * [组件 props 原子化](#组件-props-原子化) * [验证组件的 props](#验证组件的-props) @@ -42,6 +41,7 @@ * [提供组件 demo](#提供组件-demo) * [对组件文件进行代码校验](#对组件文件进行代码校验) * [只在需要时创建组件](#只在需要时创建组件) + ## 基于模块开发 @@ -218,11 +218,13 @@ Vue.js 的表达式是 100% 的 Javascript 表达式。这使得其功能性很 在 Vue.js 组件上下文中,`this`指向了组件实例。因此当你切换到了不同的上下文时,要确保 `this` 指向一个可用的 `component` 变量。 -换句话说,不要在编写这样的代码 `const self = this;` ,而是应该直接使用变量 `component`。 +换句话说,如果你正在使用 **ES6** 的话,就不要再编写 `var self = this;` 这样的代码了,您可以安全地使用 Vue 组件。 ### 为什么? -* 将组件 `this` 赋值给变量 `component`可用让开发者清楚的知道任何一个被使用的地方,它代表的是组件实例。 +* 使用 **ES6**,就不再需要将 `this` 保存到一个变量中了。 +* 一般来说,当你使用箭头函数时,会保留 `this` 的作用域。(译者注:箭头函数没有它自己的 this 值,箭头函数内的 this 值继承自外围作用域。) +* 如果你没有使用 **ES6**,当然也就不会使用 `箭头函数` 啦,那你必须将 “this” 保存到到某个变量中。这是唯一的例外。 ### 怎么做? From 6dbea2c080a1d1eba3d02d14d1baa83c7eb1e82b Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Thu, 6 Jul 2017 21:29:07 +0300 Subject: [PATCH 02/30] Fix type and Update README-RU --- README-RU.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README-RU.md b/README-RU.md index d1d92eb..2b23b96 100644 --- a/README-RU.md +++ b/README-RU.md @@ -168,9 +168,9 @@ [↑ наверх](#Содержание) -## Ограничивайте используйте свойства компонента +## Ограничивайте использование свойств компонента -В Vue свойства компонента (`props`) являются отражением его API. Ясное и понятное API делает ваши компоненты более простыми для использования другими разработчиками. +Во Vue свойства компонента (`props`) это его API. Ясное и понятное API делает ваши компоненты более простыми для использования другими разработчиками. Свойства передаются с использованием специальных атрибутов тега. Эти атрибуты могут быть либо указаны как пустые значения (`:attr`), либо присвоены строкам (`:attr="value"` или `v-bind:attr="value"`). Обратите внимание на подобные возможности при описании свойств. From 3b032ec72d5722b93aefd425a6cc3230bc5956b2 Mon Sep 17 00:00:00 2001 From: cetaju Date: Sat, 29 Jul 2017 10:19:29 +0200 Subject: [PATCH 03/30] added recommend usage of mixins --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/README.md b/README.md index 494cc98..0256348 100644 --- a/README.md +++ b/README.md @@ -628,6 +628,106 @@ Vue.js is a component framework based. Not knowing when to create components can [↑ back to Table of Contents](#table-of-contents) +## Use mixins wherever possible + +### Why? + +Mixins encapsulate reusable code and avoid duplication. If two components share the same functionality, a mixin can be used. With mixins, you can focus on the individual component task and abstract common code. This helps to better maintain your application. + +### How? + +Let's say you have a mobile and desktop menu component whose share some functionality. First, let's see how the mobile component looks like. + +```html + + + +``` + +Now let's investigate the desktop menu component. + +```html + + + +``` + +We can abstract the core functionalities of both into a mixin like this. + +```js +const MenuMixin = { + data () { + return { + language: 'EN' + } + }, + + methods: { + changeLanguage () { + if (this.language === 'DE') this.$set(this, 'language', 'EN') + if (this.language === 'EN') this.$set(this, 'language', 'DE') + } + } +} + +export default MenuMixin +``` + +To use the mixin, simply import into both components (I only show the mobile component). + +```html + + + + +[↑ back to Table of Contents](#table-of-contents) + --- ## Wanna help? From 7cb6e8727d1e03183f9113c173609c52ccd9b0fa Mon Sep 17 00:00:00 2001 From: cetaju Date: Sat, 29 Jul 2017 10:21:58 +0200 Subject: [PATCH 04/30] fixed wording and code example markdown --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0256348..ba5df82 100644 --- a/README.md +++ b/README.md @@ -709,7 +709,7 @@ const MenuMixin = { export default MenuMixin ``` -To use the mixin, simply import into both components (I only show the mobile component). +To use the mixin, simply import it into both components (I only show the mobile component). ```html