vite+vue+ts+element-plus从零开发管理后台框架(13)-个人信息

编辑src/views/Main.vuetemplateheader-right修改如下。

<div class="header-right">
    <el-dropdown trigger="click" @command="handleUserCommand">
        <span class="user-info">
            <el-icon class="el-icon--left">
                <user />
            </el-icon>
            admin
            <el-icon class="el-icon--right">
                <arrow-down />
            </el-icon>
        </span>
        <template #dropdown>
            <el-dropdown-menu>
                <el-dropdown-item command="info">个人信息</el-dropdown-item>
                <el-dropdown-item command="password">修改密码</el-dropdown-item>
                <el-dropdown-item divided command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </template>
    </el-dropdown>
</div>

script段引入并实例化router,再添加handleUserCommand方法处理下拉菜单按钮事件。

import { onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

import * as MenuUtil from '@/util/menu'
import useMenuStore from '@/store/menu'


const route = useRoute()
const router = useRouter()

const menuStore = useMenuStore()
const onCollapseSwitch = () => {
    menuStore.collapse = !menuStore.collapse
}

const handleUserCommand = (command: string) => {
    if (command == 'info') {
        router.push('/Home')
    } else if (command == 'password') {
        router.push('/sys/AdmUserPassword')
    } else if (command == 'logout') {
        // 清空登录相关信息
        router.push('/login')
    }
}

styleheader-right修改如下

.header-right {
    display: flex;
    align-items: center;

    .user-info {
        margin-right: 15px;
        cursor: pointer;
        display: flex;
        align-items: center;
    }
}

效果

默认

默认

展开(点击对应的菜单会跳转不同的路由)

点击展开

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!