File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ import persistedState from "vuex-persistedstate"; // 持久化
44export 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 : { } ,
You can’t perform that action at this time.
0 commit comments