Mixins
Besides using components, mixins are another way to reuse code. A mixin is just a plain JavaScript object that can contain any component options. As suggested by the name mixin, Vue.js mixes a mixin into your Vue components' options objects. In this way, you can write cross-component functionalities.
When a mixin and a component both contain the same options, Vue.js will merge them with different strategies, depending on the value of the option. For example, if a mixin and a component both contain a created() life cycle hook, Vue.js will put both methods into an array and call the mixin's method first. And if they both contain an option that expects object values (for example, methods, components, directives, and filters) Vue.js will ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access