Mixins

Learn about Vue's mixins, a go-to method for creating reusable code, and how they relate to inheritance.

This lesson will look at the go-to method for creating reusable code, mixins. Mixins are an excellent way to abstract away similar logic from otherwise different components. Use cases could be form validation, loading user data, or throwing custom events.

What is a mixin?

Mixins are code that we can plug into any component. They’re comparable to the modern-day PHP’s trait feature, which offers the same service. A mixin itself is a component. It provides lifecycle hooks, methods, data, computed fields, and all the things any other component offers. Let’s define a simple mixin as a renderless component:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy