From 3b032ec72d5722b93aefd425a6cc3230bc5956b2 Mon Sep 17 00:00:00 2001 From: cetaju Date: Sat, 29 Jul 2017 10:19:29 +0200 Subject: [PATCH 01/28] 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 02/28] 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