I'm trying to create a mixin that's globally available, but not automatically injected into every component. i.e. i do NOT want this: Vue.mixin({...});
I set up the project according to these instructions. This is my project structure. I also have assets/js/mixins.js
file in there containing my mixins.
I would like to be able to do this in my individual .vue files (many of my components use myMixin
but not all of them):
<script>
export default {
mixins:[myMixin],
data:{....}
}
</script>
<template>
<!-- some template code -->
</template>
So far the only way to do that is to add this line to the top of every component that needs it:
import {myMixin} from './assets/js/mixins.js"
but is there a way to do this once and have myMixin
variable available globally? I've tried including it in main.js
and in app.vue
but I still get "myMixin is not defined" error if I try to use myMixin
in any of the child components.
Or is there another way to register a mixin that doesn't require me typing the path to the mixins.js
file in each component?