mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2025-04-24 23:47:17 +08:00
Fix: serverConfig.json fetching behavior across nested routes
This commit is contained in:
parent
43b9e151cd
commit
ec5e7ebf79
1
.gitignore
vendored
1
.gitignore
vendored
@ -22,4 +22,3 @@ tests/**/coverage/
|
||||
*.njsproj
|
||||
*.sln
|
||||
tsconfig.tsbuildinfo
|
||||
.vscode/settings.json
|
||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -25,7 +25,7 @@
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
"source.fixAll.eslint": "explicit"
|
||||
},
|
||||
"iconify.excludes": ["el"],
|
||||
"cSpell.words": ["iconify", "Qrcode"]
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { App } from "vue";
|
||||
import axios from "axios";
|
||||
import { configConver } from "@/utils/rootConver";
|
||||
|
||||
let config: object = {};
|
||||
const { VITE_PUBLIC_PATH } = import.meta.env;
|
||||
|
||||
const setConfig = (cfg?: unknown) => {
|
||||
config = Object.assign(config, cfg);
|
||||
@ -31,7 +31,7 @@ export const getServerConfig = async (app: App): Promise<undefined> => {
|
||||
app.config.globalProperties.$config = getConfig();
|
||||
return axios({
|
||||
method: "get",
|
||||
url: `${VITE_PUBLIC_PATH}serverConfig.json`
|
||||
url: `${configConver()}serverConfig.json`
|
||||
})
|
||||
.then(({ data: config }) => {
|
||||
let $config = app.config.globalProperties.$config;
|
||||
|
22
src/utils/rootConver.ts
Normal file
22
src/utils/rootConver.ts
Normal file
@ -0,0 +1,22 @@
|
||||
const { VITE_PUBLIC_PATH } = import.meta.env;
|
||||
|
||||
export const configConver = () => {
|
||||
if (VITE_PUBLIC_PATH === "./") {
|
||||
return window.location.origin + "/";
|
||||
}
|
||||
return window.location.origin + processPath(VITE_PUBLIC_PATH);
|
||||
};
|
||||
|
||||
function processPath(str: string): string {
|
||||
if (str.startsWith("./")) {
|
||||
str = str.substring(1);
|
||||
} else if (!str.startsWith("/")) {
|
||||
str = "/" + str;
|
||||
}
|
||||
|
||||
if (!str.endsWith("/")) {
|
||||
str += "/";
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user