Skip to content

Commit 29aac5a

Browse files
committed
perf: 动态设置后端ip
1 parent f7517ab commit 29aac5a

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

frontend/html5/src/App.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
<template>
22
<router-view />
33
</template>
4+
5+
<script lang="ts">
6+
import { defineComponent } from "vue";
7+
import { useStore } from "vuex";
8+
export default defineComponent({
9+
name: "App",
10+
setup() {
11+
// 动态设置后端host
12+
/*
13+
2.window.location.protocol(协议)
14+
结果:http
15+
4.window.location.hostname(域名)
16+
17+
*/
18+
const protocol = window.location.protocol;
19+
const hostname = window.location.hostname;
20+
21+
const store = useStore();
22+
store.commit(
23+
"setServiceHost",
24+
`${protocol}//${hostname}`
25+
);
26+
console.log("App ")
27+
return {
28+
// 返回的数据
29+
};
30+
},
31+
});
32+
</script>

frontend/html5/src/store/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import persistedState from "vuex-persistedstate"; // 持久化
44
export default createStore({
55
state: {
66
// sever hostname
7-
serverHost: "http://192.168.0.110:8000",
7+
serverHost: "",
8+
serverPort: "8366",
89
// 用于记录当前页面是否被修改
910
changeState: false,
1011
// 是否被提交
@@ -34,6 +35,10 @@ export default createStore({
3435
state.token.accessToken = accessToken;
3536
state.token.tokenType = tokenType;
3637
},
38+
setServiceHost(state, host) {
39+
// 动态设置serverHost
40+
state.serverHost = `${host}:${state.serverPort}`;
41+
},
3742
},
3843
actions: {},
3944
modules: {},

0 commit comments

Comments
 (0)