Skip to content

Commit 03cb2cb

Browse files
committed
增加初始化 。增加if验证防止空api访问
1 parent 286674e commit 03cb2cb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/components/Layout/Sidebar.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
menus:null,
2222
}
2323
},
24+
created() {
25+
this.initData()
26+
},
2427
watch: {
2528
apiUrl:'initData'
2629
},
@@ -31,12 +34,14 @@
3134
},
3235
methods: {
3336
initData(){
34-
let _this = this
35-
let apiUrl = this.apiUrl
36-
let thenFunction = function(Response) {
37-
_this.menus = Response.data.main.menus
37+
if (this.apiUrl) {
38+
let _this = this
39+
let apiUrl = this.apiUrl
40+
let thenFunction = function(Response) {
41+
_this.menus = Response.data.main.menus
42+
}
43+
this.$store.dispatch('getData',{ apiUrl, thenFunction })
3844
}
39-
this.$store.dispatch('getData',{ apiUrl, thenFunction })
4045
}
4146
}
4247
}

0 commit comments

Comments
 (0)