Vue Mixins imported globally but only used in local components
P粉436052364
P粉436052364 2024-02-26 17:39:58
0
1
340

I want to use a mixin in multiple components without having to write import and use declarations each time. I've tried connecting the mixin object to the global variable via vue.prototype, but the mixins are added to the component before the global variable is accessible. Also, I can't import the mixin globally without adding it to all components globally (which I don't want to do). If anyone has a suitable solution that doesn't involve too much code I'd be grateful. Since this is my first question here, please feel free to leave suggestions for improvements.

Edit: I can import the mixin globally, but I want to define myself which components use the mixin.

Edit 2: Another solution is in array of mixins, but I didn't find a way to do this. Neither require() nor import() can be used.

Edit 3: I decided to stick with using the mixin locally.

P粉436052364
P粉436052364

reply all(1)
P粉754473468

Have you tried this?

main.js

import yourGlobalMixin from '@/mixins/yourGlobalMixin.js'


Vue.mixin(yourGlobalMixin)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template