2
Currently in my projects I started using Classes
in JS, especially in cases related to a specific element, for example the User, all requests HTTP
or methods related to it I usually isolate in two classes to facilitate the reuse. In the end I end up creating a Usuario.js
and UsuarioService.js
. The first only with attributes, getters and setters. And the second with the other methods.
But I’ve seen many using Mixins
for the same purpose. Do you know which of the forms would be more in line with Vue’s good development practices? Preferably use Mixin, Class or even both together?
Obs: Before I used mixins too, but I started using more classes, because I realized that people who didn’t know the Vuejs were easier to maintain codes with classes than with mixins, and understood much faster what was happening in the code.
Very interesting question but the answers can be based on personal opinion. The big problem with mixins in my opinion is that they introduce different N-places code and make it very difficult to understand how the component works. A class that inherits from another class is easier to follow the feature set that is added.
– Sergio
Very well pointed @Sergio! Actually, it is much easier to follow the features, currently I use mixin when I need to use the created, Mounted or another Vuejs resource. Thanks for pointing out that the question can send personal opinion, I will try to edit to seek more objective answers.
– Eduardo Ribeiro