File tree Expand file tree Collapse file tree 8 files changed +48
-8
lines changed Expand file tree Collapse file tree 8 files changed +48
-8
lines changed Original file line number Diff line number Diff line change 2
2
ENV = ' development'
3
3
4
4
VUE_APP_BASE_API = ' '
5
+ VUE_APP_TYPE = ' service'
5
6
6
7
# vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
7
8
# to control whether the babel-plugin-dynamic-import-node plugin is enabled.
Original file line number Diff line number Diff line change
1
+ # just a flag
2
+ ENV = 'development'
3
+
4
+ VUE_APP_BASE_API = ''
5
+
6
+ VUE_APP_TYPE = 'localhost'
7
+
8
+ # vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
9
+ # to control whether the babel-plugin-dynamic-import-node plugin is enabled.
10
+ # It only does one thing by converting all import() to require().
11
+ # This configuration can significantly increase the speed of hot updates,
12
+ # when you have a large number of pages.
13
+ # Detail: https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/babel-preset-app/index.js
14
+
15
+ VUE_CLI_BABEL_TRANSPILE_MODULES = true
Original file line number Diff line number Diff line change 5
5
"private" : true ,
6
6
"scripts" : {
7
7
"dev" : " vue-cli-service serve" ,
8
- "dev:prod " : " vue-cli-service serve --mode production " ,
8
+ "localhost " : " vue-cli-service serve --mode localhost " ,
9
9
"build" : " vue-cli-service build" ,
10
10
"lint" : " eslint --fix --ext .js,.vue src"
11
11
},
Original file line number Diff line number Diff line change 5
5
</template >
6
6
7
7
<script >
8
+ import { mapGetters } from ' vuex'
8
9
export default {
9
10
name: ' App' ,
11
+ computed: {
12
+ ... mapGetters ([
13
+ ' userInfo'
14
+ ])
15
+ },
10
16
watch: {
11
17
$route (val) {
12
18
this .invalidRoute (val)
@@ -20,6 +26,14 @@ export default {
20
26
this .$router .push (' /404' )
21
27
return
22
28
}
29
+ // 如果用户没有登录,进入这些页面将重定向到401页面
30
+ if (! this .userInfo ) {
31
+ const inaccessibleList = [' /write' ]
32
+ if (inaccessibleList .includes (val .path )) {
33
+ this .$router .push (' /401' )
34
+ return
35
+ }
36
+ }
23
37
}
24
38
}
25
39
}
Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ const user = {
26
26
setToken ( { commit } , data ) {
27
27
return new Promise ( ( resolve , reject ) => {
28
28
commit ( 'SET_TOKEN' , data )
29
- // 将数据存到缓存
30
- _setCookie ( 'token' , data )
29
+ // 设置cookie过期时间为30天
30
+ _setCookie ( 'token' , data , { expires : 30 } )
31
31
resolve ( )
32
32
} )
33
33
} ,
Original file line number Diff line number Diff line change 11
11
<li class =" link-type" >
12
12
<router-link to =" /" >回首页</router-link >
13
13
</li >
14
- <li class =" link-type" ><a href =" https://www.taobao.com/" >逛逛淘宝</a ></li >
15
- <li class =" link-type" ><a href =" https://github.com/" >刷刷github</a ></li >
14
+ <li class =" link-type" ><a href =" https://www.taobao.com/" target = " _blank " >逛逛淘宝</a ></li >
15
+ <li class =" link-type" ><a href =" https://github.com/2017coding/BBS " target = " _blank " >刷刷github</a ></li >
16
16
<li ><a href =" #" @click.prevent =" dialogVisible=true" >点我看图</a ></li >
17
17
</ul >
18
18
</el-col >
Original file line number Diff line number Diff line change @@ -285,7 +285,8 @@ export default {
285
285
.then (res => {
286
286
if (res .success ) {
287
287
if (type === ' login' ) {
288
- _setCookie (' token' , res .token )
288
+ // 设置cookie过期时间为30天
289
+ _setCookie (' token' , res .token , { expires: 30 })
289
290
// 设置cookie
290
291
this .$store .dispatch (' user/setToken' , res .token )
291
292
// 设置
Original file line number Diff line number Diff line change @@ -3,6 +3,16 @@ const path = require('path')
3
3
function resolve ( dir ) {
4
4
return path . join ( __dirname , dir )
5
5
}
6
+ function getProxy ( path , type ) {
7
+ if ( path === '/api' ) {
8
+ switch ( type ) {
9
+ case 'localhost' :
10
+ return 'http://localhost:1313'
11
+ case 'service' :
12
+ return 'https://www.lyh.red'
13
+ }
14
+ }
15
+ }
6
16
module . exports = {
7
17
publicPath : './' ,
8
18
outputDir : 'bbs' ,
@@ -18,8 +28,7 @@ module.exports = {
18
28
} ,
19
29
proxy : {
20
30
'/api' : {
21
- // target: 'http://localhost:1313',
22
- target : 'https://www.lyh.red' ,
31
+ target : getProxy ( '/api' , process . env . VUE_APP_TYPE ) ,
23
32
pathRewrite : {
24
33
'^/api' : '/api'
25
34
}
You can’t perform that action at this time.
0 commit comments