79695453

Date: 2025-07-09 10:22:27
Score: 1
Natty:
Report link

Just to add on this answer: https://stackoverflow.com/a/73597297/18322745 by @LuckyLooke

You can put the getADPs() function outside the store (e.g. in a separate file called 'ADPService.ts') and the you can fetch them in the store during state initialization as shown below:

import getADPs from '@/services/ADPService.ts';

export const listadoADPs = defineStore("listado", {
  state: () => ({
    adps: getADPs(),
  }),
  getters: {
    ...
  },
});

Then the getADP function can be like:

export default function getADPs() {
  const api = "your API URL";

  return fetch(api)
    .then((response) => response.json())
    .then(({ data }) => (return data))
    .catch((error) => console.log(error));
}
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: David Syengo