header.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="header">
  3. <div class="logo">后台管理系统</div>
  4. <div class="user-info">
  5. <el-dropdown trigger="click" @command="handleCommand">
  6. <span class="el-dropdown-link">
  7. <img class="user-logo" src="../../../static/img/img.jpg">
  8. {{username}}
  9. </span>
  10. <el-dropdown-menu slot="dropdown">
  11. <el-dropdown-item command="loginout">退出</el-dropdown-item>
  12. </el-dropdown-menu>
  13. </el-dropdown>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. name: 'linxin'
  22. }
  23. },
  24. computed:{
  25. username(){
  26. let username = localStorage.getItem('ms_username');
  27. return username ? username : this.name;
  28. }
  29. },
  30. methods:{
  31. handleCommand(command) {
  32. if(command == 'loginout'){
  33. localStorage.removeItem('ms_username')
  34. this.$router.push('/login');
  35. }
  36. }
  37. }
  38. }
  39. </script>
  40. <style scoped>
  41. .header {
  42. position: relative;
  43. box-sizing: border-box;
  44. width: 100%;
  45. height: 70px;
  46. font-size: 22px;
  47. line-height: 70px;
  48. color: #fff;
  49. }
  50. .header .logo{
  51. float: left;
  52. width:250px;
  53. text-align: center;
  54. }
  55. .user-info {
  56. float: right;
  57. padding-right: 50px;
  58. font-size: 16px;
  59. color: #fff;
  60. }
  61. .user-info .el-dropdown-link{
  62. position: relative;
  63. display: inline-block;
  64. padding-left: 50px;
  65. color: #fff;
  66. cursor: pointer;
  67. vertical-align: middle;
  68. }
  69. .user-info .user-logo{
  70. position: absolute;
  71. left:0;
  72. top:15px;
  73. width:40px;
  74. height:40px;
  75. border-radius: 50%;
  76. }
  77. .el-dropdown-menu__item{
  78. text-align: center;
  79. }
  80. </style>