Commit 2b7516a7 by 姜雷

设置建立API为单例模式

parent 9ae290f4
......@@ -152,10 +152,9 @@ export default {
item => item.menuCode === process.env.VUE_APP_DASHBOARD_CODE
);
if (dashboardPage && this.$router.options.base === '/') {
window.location.href =
location.origin + '/' + dashboardPage.menuLink;
this.$router.push({ name: 'dashboard' });
} else {
window.location.href = location.origin;
this.$router.push({ path: '/' });
}
})
.catch(err => {
......
......@@ -102,5 +102,21 @@ const createBaseFetch = config => {
}, errorHandle);
return service;
};
class ApiCreator {
constructor() {
return ApiCreator.getInstance();
}
static getInstance() {
if (ApiCreator.instance) {
} else if (window.ApiCreator) {
ApiCreator.instance = window.ApiCreator;
} else {
ApiCreator.instance = createBaseFetch;
window.ApiCreator = ApiCreator.instance;
}
return ApiCreator.instance;
}
}
export default createBaseFetch;
export default new ApiCreator();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment