[Vuejs]-What is the best way to pass this variable from the component to reposotory.js?

0👍

I used factory pattern

CommonRepository.js

import Repository from "@/plugins/axios";

export const useRepository = (resource) => {
  const getList = (params) => {
    return Repository.get(`${resource}/`, { params });
  };
...
return { getList, ... };
}

index.vue

....
import { useRepository } from "@/api/CommonRepository";
const repository = useRepository("/first");
...
methods: {
    async loadItems() {
      const { data } = await repository.getList(params);
    },
}

Leave a comment