App.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div id="app">
  3. <router-view v-if="isRouterAlive" />
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'App',
  9. provide() {
  10. // 父组件中通过provide来提供变量,在子组件中通过inject来注入变量。
  11. return {
  12. reload: this.reload
  13. }
  14. },
  15. data() {
  16. return {
  17. isRouterAlive: true
  18. }
  19. },
  20. mounted() {
  21. const session = [
  22. { key: 'username', commit: 'SET_USERNAME' },
  23. { key: 'realName', commit: 'SET_REALNAME' },
  24. { key: 'avatar', commit: 'SET_AVATAR' },
  25. { key: 'userId', commit: 'SET_USERID' },
  26. { key: 'departmentId', commit: 'SET_DEPTS' }
  27. ]
  28. session.forEach((item) => {
  29. if (sessionStorage.getItem(item.key) && this.$store.state.user[item.key] === '') {
  30. this.$store.commit(`user/${item.commit}`, sessionStorage.getItem(item.key))
  31. }
  32. })
  33. },
  34. methods: {
  35. reload() {
  36. this.isRouterAlive = false // 先关闭,
  37. this.$nextTick(function() {
  38. this.isRouterAlive = true // 再打开
  39. })
  40. }
  41. }
  42. }
  43. </script>
  44. <style lang="scss">
  45. // @import '~./styles/index.scss';
  46. @import '~./assets/font/font.css';
  47. // 设置进度条颜色
  48. #nprogress .bar {
  49. background: lighten($--color-primary, 25%) !important; //自定义颜色
  50. height: 3px !important;
  51. }
  52. </style>