App.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div id="app">
  3. <!--导航栏-->
  4. <nav-bar />
  5. <!--手机屏幕下显示的搜索框-->
  6. <div class="hidden-sm-and-up searchd"><search-box /></div>
  7. <!--下面的部分通过路由动态决定渲染与否-->
  8. <!--exclude,其值为正则,匹配到的组件的名称会被排除在keep-alive之外-->
  9. <keep-alive exclude="Collection,History">
  10. <router-view />
  11. </keep-alive>
  12. <!--页脚-->
  13. <footer-bar />
  14. <!--回到顶部按钮-->
  15. <el-backtop :visibility-height="100" :bottom="60" />
  16. </div>
  17. </template>
  18. <script>
  19. import NavBar from 'components/layout/NavBar'
  20. import SearchBox from 'components/layout/SearchBox'
  21. import FooterBar from 'components/layout/FooterBar'
  22. export default {
  23. name: 'App',
  24. components: {
  25. FooterBar,
  26. SearchBox,
  27. NavBar
  28. },
  29. created() {
  30. /**
  31. * 防止vuex中的state在界面刷新后丢失
  32. */
  33. // 在页面加载时读取sessionStorage里的状态信息
  34. if (sessionStorage.getItem('store')) {
  35. this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))))
  36. }
  37. // 在页面刷新时将vuex里的信息保存到sessionStorage里
  38. window.addEventListener('beforeunload', () => {
  39. sessionStorage.setItem('store', JSON.stringify(this.$store.state))
  40. })
  41. },
  42. methods: {
  43. }
  44. }
  45. </script>
  46. <style>
  47. @import "assets/css/base.css";
  48. #app {
  49. overflow-y: scroll;
  50. }
  51. .searchd {
  52. margin-top: 15px;
  53. text-align: center;
  54. }
  55. /*.fade-enter-active,.fade-leave-active {
  56. -webkit-transition:opacity 1s;
  57. transition:opacity 1s
  58. }
  59. .fade-enter,.fade-leave-to {
  60. opacity:0
  61. }*/
  62. </style>