页面头部抖动问题解决办法

页面头部我采取flex布局的方式,vue的框架+elementplus,

这种方式会造成页面的头部抖动,字体重叠问题;[现象的视频-头部抖动]

上原有问题的代码:

模版中的代码(没问题):

<template>
    <div class="layout-container" >
        <header class="layout-header">
            <div class="header-left">
                <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" text-color="#04fbfe"
                    active-text-color="#fff" background-color="transparent" router @select="selectMenu">
                    <!--<el-menu-item index="/home">首页</el-menu-item>-->
                    <!-- <el-menu-item
                        index="/mainframe"
                        v-if="userInfo.manualoiling === 1"
                        >设备管理</el-menu-item
                    >-->
                    <!-- style="left:-42%" -->
                    <el-menu-item index="/home">设备管理</el-menu-item>

                </el-menu>
                <div class="time">
                    <div class="time-icon"></div>
                    <span>{{ nowDate }}</span>
                </div>
            </div>
            <div class="header-center">小保当煤矿智能润滑监控系统</div>
            <div class="header-right">
                <div class="header-menu">
                    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" text-color="#04fbfe"
                        active-text-color="#fff" background-color="transparent" router @select="selectMenu">
                        <!--<el-menu-item index="/statepreview"
                            ></el-menu-item
                        >-->
                        <el-menu-item></el-menu-item>
                        <el-menu-item index="/historydata">历史数据</el-menu-item>
                        <el-menu-item index="/setparams" v-if="userInfo.plcsetting === 1">参数设置</el-menu-item>
                        <el-menu-item index="/usermanage" v-if="userInfo.usermanager === 1">用户管理</el-menu-item>
                        <el-menu-item v-if="userInfo.singlepointstatusbrowse === 1"
                            index="/SuperControlPlatform">智能润滑监控平台</el-menu-item>
                        <!-- <el-menu-item
                            index="/IntellectLubeSuperControlPlatform"
                            >智能润滑监控平台</el-menu-item
                        >-->
                        <el-menu-item v-if="userInfo.singlepointmanager === 1"
                            index="/SinglePointDeviceManage">单点注油器设备管理</el-menu-item>
                        <!-- <el-menu-item
                            index="/MapTest"
                            >测试地图大屏展示</el-menu-item
                        >-->
                        <el-menu-item v-if="userInfo.singlepointdatamanager === 1"
                            index="/SinglePointPourIntoOil">单点注油</el-menu-item>
                        <el-menu-item v-if="userInfo.singlepointrepeatermanager === 1"
                            index="/MACData">中继网关信道管理</el-menu-item>
                        <!--<el-menu-item
                            index="/MainPage"
                            >主机列表</el-menu-item
                        >
                        <el-menu-item
                            index="/MainPageTwo"
                            >主机列表2</el-menu-item
                        >-->
                        <!--<el-menu-item
                            index="/MainPageThree"
                            >主机列表3</el-menu-item
                        >-->
                    </el-menu>
                </div>
                <el-dropdown @command="clickDropdown">
                    <span class="el-dropdown-link el-users-link">
                        {{ userInfo.username }}
                        <span class="user-icon"></span>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="exit">退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </header>
        <div class="layout-main">
            <RouterView />
        </div>
        <div class="layout-footer"></div>
    </div>
</template>

js代码(没问题):

<script setup lang="ts">
import { RouterView, useRoute, useRouter } from 'vue-router';
import { ref, onMounted, onBeforeUnmount, onBeforeMount } from 'vue';
import { ElMessage } from 'element-plus';
//import { el } from 'element-plus/es/locale';
import { ValidateToken, GetTokenByID } from '@/api/login-api';
const route = useRoute();
const router = useRouter();

const activeIndex = ref('');

const getQueryString = (name: string) => {
    let geturl = window.location.href;
    let getqyinfo = geturl.split('?')[1]   //qycode=1001&qyname=%E4%BC%81%E4%B8%9A%E5%BF%99   截取到参数部分
    let getqys = new URLSearchParams('?' + getqyinfo)  //将参数放在URLSearchParams函数中
    return getqys.get(name);  //1001   
}
onBeforeMount(async () => {
    if (window.TokenMethod === 1) {

        if (localStorage.getItem('token') as string) {
            debugger;
            let params = { Token: localStorage.getItem('token') as string };
            const { data: res } = await ValidateToken(params);

            userInfo.value = res.userInfo;
            if (!userInfo.value) {
                ElMessage.error('请登录后再访问');
                router.push('/login');
            }
        }
        else {

            var TokenId = getQueryString('TokenID');
            let params = { ID: TokenId };
            const { data: res } = await GetTokenByID(params);
            if (res.data.length > 0) {
                localStorage.setItem('token', res.data[0].TokenValue);
                let paramss = { Token: localStorage.getItem('token') as string };
                const { data: ress } = await ValidateToken(paramss);

                userInfo.value = ress.userInfo;
                if (!userInfo.value) {
                    ElMessage.error('请登录后再访问');
                    router.push('/login');
                }
            }
            else {
                ElMessage.error('请登录后再访问');
                router.push('/login');
            }

        }
    }
    else {
        userInfo.value = JSON.parse(sessionStorage.getItem('dyuser') as string);
    }
    // console.log(userInfo.value.usermanager);
    // if (!userInfo.value) {
    //     ElMessage.error('请登录后再访问');
    //     router.push('/login');
    // }
});

onMounted(() => {
    activeIndex.value = route.path;
    getNowDate();
    currentTime();
});

onBeforeUnmount(() => {
    // 清除时间
    if (getNowDate) {
        clearInterval(getNowDate as any);
    }
});

const userInfo = ref();

// 下拉框点击
const clickDropdown = (item: string) => {
    if (item === 'exit') {
        router.push('/login');
        sessionStorage.removeItem('dyuser');
        localStorage.removeItem('token');
    }
};

// 菜单选中
const selectMenu = (index: string) => {
    activeIndex.value = index;
};

// 当前时间
const nowDate = ref('');
// 获取当前时间
const getNowDate = () => {
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1; // 月
    let day = date.getDate();
    let week = date.getDay();
    let weekArr = [
        '星期日',
        '星期一',
        '星期二',
        '星期三',
        '星期四',
        '星期五',
        '星期六',
    ];
    let hour: any = date.getHours();
    hour = hour < 10 ? '0' + hour : hour;
    let minute: any = date.getMinutes();
    minute = minute < 10 ? '0' + minute : minute;

    nowDate.value = `${year}/${month}/${day} ${hour}:${minute} ${weekArr[week]}`;
};

// 定时刷新时间
const currentTime = () => {
    setInterval(getNowDate, 10000);
};
</script>

css代码(看头部的layout-header):

<style lang="scss" scope>
[v-cloak] {
    display: none !important;
}

.layout-container {
    min-height: 100vh;
    background: url('../assets/images/common-images/bg.jpg') no-repeat center;
    background-size: 100% 100%;
    display: flex;
    flex-direction: column;
}

.layout-header {
    // min-height: 70px;
    height: 70px;
    background: url('../assets/images/common-images/header.png') no-repeat center;
    background-size: 100% 100%;
    display: flex;//因为flex布局造成宽度不足,会出现头部抖动,解决办法就是给一个100%的宽度


    >div {
        flex: 1;
        color: aliceblue;
    }

    .header-left {
        margin: 0 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 20px;
        color: #04fbfe;
        font-size: 18px;

        .time {
            display: flex;
            padding-right: 5px;

            .time-icon {
                display: inline-block;
                width: 24px;
                height: 24px;
                margin-right: 10px;
                background: url('../assets/images/common-images/icon_clock.png') no-repeat center;
                background-size: contain;
            }

            .week {
                margin-left: 5px;
                font-size: 12px;
            }
        }

        .weather {
            display: flex;
            align-items: center;

            .weather-icon {
                display: inline-block;
                width: 24px;
                height: 24px;
                margin-right: 10px;
                background: url('../assets/images/common-images/icon_weather.png') no-repeat center;
                background-size: cover;
            }
        }

        .envir-label {
            font-size: 12px;
            margin-right: 10px;
        }

        .air-num {
            color: #fd9203;
        }

        .el-menu {
            flex: 1;
        }
    }

    .header-right {
        margin-right: 20px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 20px;
        color: #04fbfe;

        .header-menu {
            flex: 1;
            // display: flex;
            justify-content: space-evenly;

            .el-menu-item {
                font-size: 16px;
            }

            span {
                flex: 1;
                text-align: center;
                cursor: pointer;
                line-height: 1;
                letter-spacing: 2px;
                font-size: 18px;
            }

            span+span {
                border-left: 1px solid;
            }
        }
    }

    .header-center {
        font-size: 30px;
        font-weight: 700;
        display: grid;
        place-items: center;
        letter-spacing: 5px;
        transform: translateY(-12%);
    }

    .el-users-link {
        cursor: pointer;
        color: #04fbfe;
        display: flex;
        align-items: center;
        font-size: 16px;

        .user-icon {
            display: inline-block;
            width: 24px;
            height: 24px;
            margin-left: 10px;
            background: url('../assets/images/common-images/icon_user.png') no-repeat center;
            background-size: contain;
        }
    }
}

.layout-main {
    color: #fff;
    padding: 0 20px;
    // padding-bottom: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    flex: 1;
}

.el-menu {
    background-color: transparent;
    border-bottom: 0;
    justify-content: space-evenly;

    .el-menu-item {
        font-size: 16px;
        border-bottom: 0;
    }

    .el-menu-item.is-active {
        border-bottom: 0;
        background-color: rgba($color: #000000, $alpha: 0.3);
    }
}

.layout-footer {
    color: #04fbfe;
    font-size: 14px;
    text-align: right;
    letter-spacing: 2px;
    margin-bottom: 5px;
    margin-right: 20px;
}
</style>

解决后的代码css:

<style lang="scss" scope>


.layout-container {
    min-height: 100vh;
    background: url('../assets/images/common-images/bg.jpg') no-repeat center;
    background-size: 100% 100%;
    display: flex;
    flex-direction: column;
}

.layout-header {
    width: 100%;
    // min-height: 70px;
    height: 70px;
    background: url('../assets/images/common-images/header.png') no-repeat center;
    background-size: 100% 100%;
    display: flex;


    >div {
        flex: 1;
        color: aliceblue;
    }

    .header-left {
        margin: 0 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 20px;
        color: #04fbfe;
        font-size: 18px;

        .time {
            display: flex;
            padding-right: 5px;

            .time-icon {
                display: inline-block;
                width: 24px;
                height: 24px;
                margin-right: 10px;
                background: url('../assets/images/common-images/icon_clock.png') no-repeat center;
                background-size: contain;
            }

            .week {
                margin-left: 5px;
                font-size: 12px;
            }
        }

        .weather {
            display: flex;
            align-items: center;

            .weather-icon {
                display: inline-block;
                width: 24px;
                height: 24px;
                margin-right: 10px;
                background: url('../assets/images/common-images/icon_weather.png') no-repeat center;
                background-size: cover;
            }
        }

        .envir-label {
            font-size: 12px;
            margin-right: 10px;
        }

        .air-num {
            color: #fd9203;
        }

        .el-menu {
            flex: 1;
        }
    }

    .header-right {
        margin-right: 20px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 20px;
        color: #04fbfe;

        .header-menu {
            flex: 1;
            // display: flex;
            justify-content: space-evenly;

            .el-menu-item {
                font-size: 16px;
            }

            span {
                flex: 1;
                text-align: center;
                cursor: pointer;
                line-height: 1;
                letter-spacing: 2px;
                font-size: 18px;
            }

            span+span {
                border-left: 1px solid;
            }
        }
    }

    .header-center {
        font-size: 30px;
        font-weight: 700;
        display: grid;
        place-items: center;
        letter-spacing: 5px;
        transform: translateY(-12%);
    }

    .el-users-link {
        cursor: pointer;
        color: #04fbfe;
        display: flex;
        align-items: center;
        font-size: 16px;

        .user-icon {
            display: inline-block;
            width: 24px;
            height: 24px;
            margin-left: 10px;
            background: url('../assets/images/common-images/icon_user.png') no-repeat center;
            background-size: contain;
        }
    }
}

.layout-main {
    color: #fff;
    padding: 0 20px;
    // padding-bottom: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    flex: 1;
}

.el-menu {
    background-color: transparent;
    border-bottom: 0;
    justify-content: space-evenly;

    .el-menu-item {
        font-size: 16px;
        border-bottom: 0;
    }

    .el-menu-item.is-active {
        border-bottom: 0;
        background-color: rgba($color: #000000, $alpha: 0.3);
    }
}

.layout-footer {
    color: #04fbfe;
    font-size: 14px;
    text-align: right;
    letter-spacing: 2px;
    margin-bottom: 5px;
    margin-right: 20px;
}
</style>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值