Know All About Mixin Use In Vue Js With Example

  • 20-06-2022
  • 646
  • Vue
  • Haresh Chauhan

Vue Mixins are a flexible way to distribute a single code among all the component in the vue js project. which is reusable functionalities for the vue components.

In another word, we can say Mixins is a class of contains a method for other classes. They share the reusable code and property among the components.

The Mixins component object can contain any component of the project when you call that mixin asset into the component it will use mixins.

All the options in the mixin will be the part and asset of the that called own component or when you called mixin in the component that mixin object class property will be that part.

In Mixins we can define all that scrip which we define in root component but the difference is that defined mixin asset like methods and computed property can reusable many more time.

This will reduce your repetitive code and max reusable of your same methods and property.

So it writes one time and uses it over and over among the vue project component.



Here below I have given an example of the uses of mixin in vuejs.


This is my mixin asset here I have to define a computed property so I can use that filter for the next component.

This computed property will filter that given data. Here we can also define the method and data property too.


export default {
    computed: {
        filterBlog() {
            return this.items.filter((blog) => {
                return blog.title.match(


This is our ExampleComponent where I will import that mixins asset with the name of searchMixins.

After importing that mixin asset define in mixins property.


    <div class="container">
        <div class="form-group my-5">
            <label for="search">Search Title:</label>
            <input class="form-control" type="search" v-model="search">
            <li v-for="(item,index) in filterBlog" :key="index">
                <span style="color:green">{{ item.title }}</span>
                <p style="color:red">{{ item.body }}</p>

import searchMixins from '../mixins/searchMixins' // IMPORT MIXIN 

export default {

        return {


        this.axios.get('').then((response) => {
            this.items =

    mixins:[searchMixins] //CALLED MIXIN


This is my root app component, Here I called my example component So we can display output.


    <div id="app">


import ExampleComponent from './components/ExampleComponent.vue'

export default {
    name: 'App',

    components: {

We always thanks to you for reading our blogs.


Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us


Haresh Chauhan


We Are Also Recommending You :