Classes, Mixins or the Two?

3

Currently in my projects I started using Classes in JS, mainly in cases related to a certain specific element, for example, User, all HTTP requests or methods related to it I usually isolate in two classes to facilitate reuse. In the end I end up creating Usuario.js and UsuarioService.js . The first only with attributes, getters and setters. And the second with the other methods.

But I have seen many using Mixins for the same purpose. Do you know which way would be more in keeping with Vue's good development practices? Preferably use Mixin, Class or even the two together?

Obs: Before I used mixins too, I started to use more classes because I realized that people who did not know VueJS with classes than with mixins, in addition to understanding much faster what was happening in the code.

    
asked by anonymous 13.11.2018 / 15:44

1 answer

1

I do not see much of the advantage of using a class with only getters and setters, but I see an advantage in using the services, an approach that helped to clarify more ideas about it were these two very good articles. They helped me see how to isolate the layers and have a cleaner component as possible.

link link

    
15.11.2018 / 15:05