11import './index.less' ;
22
3- import { defineComponent , unref , computed , ref } from 'vue' ;
3+ import { defineComponent , unref , computed , ref , nextTick } from 'vue' ;
44
55import { Layout , Tooltip , Badge } from 'ant-design-vue' ;
66import { AppLogo } from '/@/components/Application' ;
@@ -39,8 +39,8 @@ export default defineComponent({
3939 setup ( ) {
4040 let logoEl : Element | null ;
4141
42- const widthRef = ref ( 200 ) ;
43-
42+ const logoWidthRef = ref ( 200 ) ;
43+ const logoRef = ref < any > ( null ) ;
4444 const { refreshPage } = useTabs ( ) ;
4545
4646 const { getShowTopMenu, getShowHeaderTrigger, getSplit, getTopMenuAlign } = useMenuSetting ( ) ;
@@ -64,15 +64,17 @@ export default defineComponent({
6464
6565 useWindowSizeFn (
6666 ( ) => {
67- if ( ! unref ( getShowTopMenu ) ) return ;
68- let width = 0 ;
69- if ( ! logoEl ) {
70- logoEl = document . querySelector ( '.layout-header__logo' ) ;
71- }
72- if ( logoEl ) {
73- width += logoEl . clientWidth ;
74- }
75- widthRef . value = width + 60 ;
67+ nextTick ( ( ) => {
68+ if ( ! unref ( getShowTopMenu ) ) return ;
69+ let width = 0 ;
70+ if ( ! logoEl ) {
71+ logoEl = logoRef . value . $el ;
72+ }
73+ if ( logoEl ) {
74+ width += logoEl . clientWidth ;
75+ }
76+ logoWidthRef . value = width + 80 ;
77+ } ) ;
7678 } ,
7779 200 ,
7880 { immediate : true }
@@ -105,11 +107,11 @@ export default defineComponent({
105107 }
106108
107109 function renderHeaderContent ( ) {
108- const width = unref ( widthRef ) ;
110+ const width = unref ( logoWidthRef ) ;
109111 return (
110112 < div class = "layout-header__content " >
111113 { unref ( getShowHeaderLogo ) && (
112- < AppLogo class = { `layout-header__logo` } theme = { unref ( getTheme ) } />
114+ < AppLogo class = { `layout-header__logo` } ref = { logoRef } theme = { unref ( getTheme ) } />
113115 ) }
114116
115117 { unref ( getShowContent ) && (
0 commit comments