App.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="af-entry">
  3. <keep-alive>
  4. <router-view v-if="$route.meta.keepAlive"></router-view>
  5. </keep-alive>
  6. <router-view v-if="!$route.meta.keepAlive"></router-view>
  7. <van-tabbar
  8. class="af-entry-tabbar"
  9. v-model="activeTab"
  10. :placeholder="true"
  11. v-show="$route.meta.isUseVanTabbar"
  12. @change="onChange">
  13. <van-tabbar-item
  14. name="PlaceList"
  15. icon="wap-home-o">订座
  16. </van-tabbar-item>
  17. <van-tabbar-item
  18. name="PlaceReserve"
  19. icon="user-o">我的订座
  20. </van-tabbar-item>
  21. </van-tabbar>
  22. </div>
  23. </template>
  24. <script>
  25. import { Tabbar, TabbarItem } from 'vant'
  26. export default {
  27. name: 'App',
  28. components: {
  29. 'van-tabbar': Tabbar,
  30. 'van-tabbar-item': TabbarItem
  31. },
  32. data () {
  33. return {
  34. activeTab: 'PlaceList'
  35. }
  36. },
  37. watch: {
  38. '$route.name': {
  39. handler: function (newVal) {
  40. this.activeTab = newVal
  41. },
  42. immediate: true
  43. }
  44. },
  45. async created () {
  46. await this.$store.dispatch('common/fetchBarList')
  47. },
  48. mounted () {
  49. const routeName = this.$route.name
  50. this.activeTab = ['PlaceList', 'PlaceReserve'].findIndex(item => item === routeName) > -1 ? routeName : ''
  51. },
  52. methods: {
  53. onChange (routeName) {
  54. this.$router.replace({ name: routeName })
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="scss">
  60. @import "./assets/styles/reset";
  61. .clearfix {
  62. display: inline-block;
  63. &:after {
  64. display: block;
  65. content: ".";
  66. height: 0;
  67. line-height: 0;
  68. clear: both;
  69. visibility: hidden;
  70. }
  71. }
  72. .af-entry {
  73. height: 100%;
  74. overflow-y: scroll;
  75. -webkit-overflow-scrolling: touch;
  76. background: #F2F2F2;
  77. &-tabbar {
  78. .van-tabbar--fixed {
  79. box-shadow: 0px -2px 4px 0px rgba(13, 13, 13, 0.03);
  80. }
  81. }
  82. }
  83. </style>