How Do We Move Forward in Life?

During our lifetime we humans reach every day new heights in our spiritual development. At least that should be the case. If I look at myself, then I don’t want to be one day younger, because that…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Component vs Mixins vs Plugins in Vue.js

Which is the best choice?

In trendings of repositories with a lot of stars, for sure Vue.js is a good framework to work with. The simplicity to solve problems and the facility to learn it is the most common talks about this. At the hand of a handful of files, you can do everything you want, from building a simple page to a complex one.

In Vue.js you can implement Components, Mixins and Plugins, but exists some differences between these methods and the correct application to each one. To start thinking in which to choose we need to know the basics about all of these.

Menu item component

They are the high level of a Vue application and compose layout or functionalities to your program. In the most times, developers opt for that because of the reuse or facility to replicate in others parts. Components can be extended getting the aspects of a parent component to the child.

An example of global mixin

Mixins are options of a component that can be accessed in any component, in several times this avoids the rework and allow to write less. They can be local, that is created and accessed only once in a component or global, it will affect every Vue instances. Already ahead that as a personal option, I choose to use plugins instead of mixins.

An example of plugin

Plugins are uses that can be accessed in any component and depends on your use. Things like router, state management and even actions that are realized can be a plugin that will be imported and used globally. For example, you can write a global method as a plugin and, any component will have access to this functionality.

Components inevitably will be in your project, because Vue is based in components, even using only CDN (without use vue-cli) you’ll construct components to compose your application. The real decision is between Mixins and Plugins, and for these have some pros that need to be considered

Mixins Pros

Plugins Pros

As I said before, I prefer to use plugins instead of mixins because of the functionalities that can be implemented using this, but mixins have them on pros and you might consider this before start writing code.

I hope that this article can be useful to you and any doubt can be answered. Thanks a lot!

Add a comment

Related posts:

NEVER FORGET 3 TYPES OF PEOPLE IN YOUR LIFE

Unpleasant people make us realize the value of real friends. As Marcel Proust put it, “Let us be grateful to people who make us happy, they are the charming gardeners who make our souls blossom.”

Highlights

We are thrilled to celebrate 5 years of Ontology MainNet! Join us as we reflect on our remarkable journey, significant milestones, and the exciting developments that have shaped the past year…

Was Neeyat star Vidya Balan cheated on in the past? Actress reveals

Bollywood actress Vidya Balan will soon be seen as a detective in her upcoming film Neeyat, which will release on July 7th. The actress returns to the big screens after four years in what promises to…