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);
},
}
Source:stackexchange.com