HeaderBar.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="header">
  3. <div class="container">
  4. <a href="">
  5. <div class="logo">
  6. <img src="../assets/images/logo.jpg"
  7. alt="">
  8. </div>
  9. </a>
  10. <div class="nav">
  11. <ul>
  12. <li :class="{'active': item.active}" v-for="item in navList" @click="select(item)">
  13. <div>{{item.name}}</div>
  14. </li>
  15. </ul>
  16. </div>
  17. <div class="logout">
  18. <div class="username">{{loginId}}</div>
  19. <el-button @click="logout" class="logout-btn">注销</el-button>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. data () {
  27. return {
  28. navList: [{
  29. path: 'themeList',
  30. name: 'h5多页作品',
  31. active: false
  32. }, {
  33. path: 'spaList',
  34. name: 'h5长单页作品',
  35. active: false
  36. }
  37. ],
  38. loginId: window.localStorage.getItem('loginId')
  39. }
  40. },
  41. methods: {
  42. select (item) {
  43. this.$router.push(item.path)
  44. },
  45. logout () {
  46. this.$store.dispatch('logout')
  47. .then(res => {
  48. this.$router.push('login')
  49. })
  50. }
  51. },
  52. mounted () {
  53. this.navList.forEach((element) => {
  54. if (element.path === this.$route.name) {
  55. element.active = true
  56. } else if (this.$route.name === 'index') {
  57. this.navList[0].active = true
  58. }
  59. })
  60. }
  61. }
  62. </script>
  63. <style lang="less">
  64. .header {
  65. width: 100%;
  66. height: 60px;
  67. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  68. background-color: #fff;
  69. }
  70. .header .container {
  71. margin: 0 auto;
  72. width: 1024px;
  73. text-align: center;
  74. }
  75. .logout {
  76. float: right;
  77. display: flex;
  78. align-items: center;
  79. height: 65px;
  80. .username {
  81. margin-right: 10px;
  82. }
  83. }
  84. .header .logo img {
  85. float: left;
  86. height: 50px;
  87. }
  88. .header .nav {
  89. float: left;
  90. padding-left: 50px;
  91. }
  92. .header .nav li {
  93. float: left;
  94. width: 110px;
  95. line-height: 52px;
  96. border-top: solid 5px rgba(0, 0, 0, 0);
  97. text-align: center;
  98. list-style: none;
  99. }
  100. .header .nav li.active {
  101. border-top: solid 5px #0059f1;
  102. }
  103. .header .nav li div {
  104. height: 60px;
  105. font-size: 16px;
  106. color: #000;
  107. cursor: pointer;
  108. }
  109. .header .nav li.active div {
  110. color: #0059f1;
  111. }
  112. </style>