Skip to content

Commit

Permalink
perf: 动态设置后端ip
Browse files Browse the repository at this point in the history
  • Loading branch information
lczmx committed Mar 5, 2022
1 parent f7517ab commit 29aac5a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
29 changes: 29 additions & 0 deletions frontend/html5/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
<template>
<router-view />
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useStore } from "vuex";
export default defineComponent({
name: "App",
setup() {
// 动态设置后端host
/*
2.window.location.protocol(协议)
结果:http
4.window.location.hostname(域名)
*/
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const store = useStore();
store.commit(
"setServiceHost",
`${protocol}//${hostname}`
);
console.log("App ")
return {
// 返回的数据
};
},
});
</script>
7 changes: 6 additions & 1 deletion frontend/html5/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import persistedState from "vuex-persistedstate"; // 持久化
export default createStore({
state: {
// sever hostname
serverHost: "http://192.168.0.110:8000",
serverHost: "",
serverPort: "8366",
// 用于记录当前页面是否被修改
changeState: false,
// 是否被提交
Expand Down Expand Up @@ -34,6 +35,10 @@ export default createStore({
state.token.accessToken = accessToken;
state.token.tokenType = tokenType;
},
setServiceHost(state, host) {
// 动态设置serverHost
state.serverHost = `${host}:${state.serverPort}`;
},
},
actions: {},
modules: {},
Expand Down

0 comments on commit 29aac5a

Please sign in to comment.