headPortrait.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div class="head">
  3. <el-popover placement="bottom" width="200" trigger="click">
  4. <div class="border">
  5. <p id="character">已登录用户:</p>
  6. <p id="character-yh">{{ this.username == ""?this.name:this.username }}</p>
  7. </div>
  8. <el-divider></el-divider>
  9. <div class="btn">
  10. <el-link icon="el-icon-unlock" @click="loginout"
  11. >退出登录<i class="-icon--right"></i>
  12. </el-link>
  13. </div>
  14. <el-button
  15. style="border-radius: 50px"
  16. icon="el-icon-user-solid"
  17. type="warning"
  18. slot="reference"
  19. ></el-button>
  20. </el-popover>
  21. </div>
  22. </template>
  23. <script>
  24. import { mapGetters, mapMutations } from "vuex";
  25. export default {
  26. data() {
  27. return {
  28. name:localStorage.getItem('username')
  29. };
  30. },
  31. computed: {
  32. // 使用对象展开运算符将 getter 混入 computed 对象中
  33. ...mapGetters(["username"]),
  34. },
  35. mounted() {
  36. window.onload=function() {
  37. this.name = localStorage.getItem('username');
  38. }
  39. },
  40. methods: {
  41. ...mapMutations("user", ["REMOVE_TOKEN"]),
  42. loginout() {
  43. this.REMOVE_TOKEN();
  44. },
  45. },
  46. };
  47. </script>
  48. <style>
  49. .border {
  50. display: flex;
  51. justify-content: center;
  52. align-items: center;
  53. }
  54. #character {
  55. display: flex;
  56. font-size: 16px;
  57. }
  58. #character-yh {
  59. font-size: 25px;
  60. margin-left: 6px;
  61. }
  62. .btn {
  63. display: flex;
  64. justify-content: center;
  65. align-items: center;
  66. }
  67. </style>