Classes, Mixins or the Two?

Asked

Viewed 88 times

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.

  • 3

    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.

  • 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.

1 answer

1


  • Very interesting articles, helped me a lot, thank you very much for the information. Actually these classes for getters and setters only help me in very specific cases, but it is nothing that the computed or methods can not replace, I use them because in the company I work only have me in the Front, and time or other the back crowd comes to give maintenance on something, so that way makes their lives easier, finally it is a very particular and "suggested" case from above kk.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.