[Vuejs]-Structuring js files vue cli project

0👍

Q1: Usually API calls are stored under a respective store if you are using Vuex. If not you can use define them as mixins and use where necessary. The mixins are the parts of the javascript code that are reused in different components. In a mixin you can put any component’s methods from Vue.js they will be merged with the ones of the component that uses it.

Q2: This can definitely go under mixins.

You can also have a util folder (optional) where it contains the functions that you use in components, such as regex value testing, constants, or filters.

Refer to this boilerplate if your project is mid-scale or large-scale.

0👍

create a service folder,create service.js -api call goes here(now all you need is to call it when ever you need it)
you have a store folder with store.js(index.js) inside store folder create modules folder
with you modules. inside store.js create modules:[user,event…]
basically that’s it. edit your modules files event.js user.js.
you can add getters,mutations,state,actions. just dont forget export const namespaced = true so it`ll go to the global namespace

Leave a comment