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!