DEV Community

Discussion on: What are services in Vue?

Collapse
 
firstclown profile image
Joe Erickson

Good question! I think this is a hard one to answer though. I always have to think "What am I using this service for?" and "How applicable will this service be outside of Vue?"

If the service is really only for my Vue application or even for a couple of components, I'll make it a Vue mixin or filter. (I'm starting to get away from filters because they aren't supported in Vue 3.)

If they can be used outside of Vue or maybe by other classes in a Vue-based application, I'll export functions or an object instead. Regular JavaScript and TypeScript code doesn't really understand the Vue mixin, so making them regular functions or objects make them more universally usable by other parts of my system or other applications I may build and want to use them in.

Thank you for the question!

Collapse
 
maureento8888 profile image
Maureen T'O

Thank you for the answer! Hmm it definitely makes sense to create the services around its usage in a Vue app. I agree, filters aren’t the best and are deprecated in v3 and mixins... well have their own downfalls, but this explains the usage of services well. Going to learn more about this and thank you! πŸ˜„πŸ™ŒπŸΌ