0

I have a mixin in my Vue project. But, it's not working. Here's the code:

InvMixin.js

export default {
    created() {
        console.log("hi");
    },

    methods: {
        helloa() {
            console.log('hi from mixin');
        },
        proal() {
            console.log("hoye");
        }
    }
}

template

import invMixin from "./InventoryMixin.js";
export default {

  mixins: [invMixin],

 methods: {
        check() {
            this.helloa();
        }
    }
}

Output

helloa is referenced but not defined Created of mixin not working

Can someone help to solve it, please? Thankyou!!

4
  • please share a bit more of template.vue, specifically between the import and the methods Commented Feb 3, 2020 at 19:40
  • which is the real name of the mixin ? InventoryMixin or invMixin, try using only one Commented Feb 4, 2020 at 2:54
  • Is path of InventoryMixin.js is correct ? Just asking to be clear. Commented Feb 4, 2020 at 7:32
  • This should work perfecly well except the code you posted isn't the same you're using. The only case I had that is simmilar to yours is when I accidently placed the mixins:[] inside of a prop which threw no errors. Commented Feb 17, 2021 at 11:23

1 Answer 1

2

Just importing your mixin is not enough. Declare it in your component:

// In your component
import invMixin from "./InventoryMixin.js";

export default {
  name: "MyComponent",
  mixins: [invMixin] //declare mixin here
}
Sign up to request clarification or add additional context in comments.

2 Comments

Done, still the same
@idk there are any differences between imvMixin.js and InventoryMixin.js? And schow the complete component where you are using the mixin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.