From dd7d2d315048333974f23d08ce5fb44ec0d9e064 Mon Sep 17 00:00:00 2001
From: “dzb” <2632970487@qq.com>
Date: 星期五, 04 十一月 2022 11:45:57 +0800
Subject: [PATCH] 修改页面渲染数据未获取报错
---
src/views/layout/components/Header/index.vue | 27 +++++++++++++++++----------
src/views/layout/components/Main/index.vue | 1 -
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/views/layout/components/Header/index.vue b/src/views/layout/components/Header/index.vue
index 8525a7c..b193bcb 100644
--- a/src/views/layout/components/Header/index.vue
+++ b/src/views/layout/components/Header/index.vue
@@ -1,6 +1,6 @@
<template>
<!-- 澶撮儴 -->
- <el-header>
+ <el-header v-if="show">
<!-- 宸︿晶鑿滃崟 -->
<div class="header-left">
<div class="menu-left__item" v-for="(item, index) in menuLeftList" :key="item.id" @click="changeActive(index)">
@@ -157,10 +157,12 @@
],
keyword: '',
info:null,
+ show:false
};
},
created() {
- this.getLoginInfo();
+ this.setLoginInfo()
+ console.log(this.user)
},
methods: {
baseInfo() {
@@ -211,22 +213,27 @@
}
})
},
- // 鑾峰彇鐧诲綍鐢ㄦ埛淇℃伅
- getLoginInfo() {
+ // 璁剧疆鐢ㄦ埛鍩烘湰淇℃伅
+ async setLoginInfo() {
const info = JSON.parse(sessionStorage.getItem('user'));
if (info) {
+ console.log(info)
this.user = info;
} else {
+ this.user = await this.getLoginInfo();
+ console.log(this.user)
+ }
+ this.show = true
+ },
+ // 鑾峰彇鐧诲綍鐢ㄦ埛淇℃伅
+ async getLoginInfo(){
const name = sessionStorage.getItem('name');
- this.$axios({
+ let res = await this.$axios({
method: 'get',
url: 'sccg/admin/info?name=' + name,
})
- .then(res => {
- sessionStorage.setItem('user', JSON.stringify(res.data));
- this.user = res.data;
- })
- }
+ sessionStorage.setItem('user', JSON.stringify(res.data));
+ return res.data
}
}
};
diff --git a/src/views/layout/components/Main/index.vue b/src/views/layout/components/Main/index.vue
index a4f4966..2d173a7 100644
--- a/src/views/layout/components/Main/index.vue
+++ b/src/views/layout/components/Main/index.vue
@@ -181,7 +181,6 @@
methods:{
handleJump(url){
const baseURL = '/home'
- console.log(url)
// 璺敱璺宠浆
this.$router.push({path:baseURL+url})
}
--
Gitblit v1.8.0