Tabbar.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <div>
  3. <van-tabbar v-model="active" @change="onChange()">
  4. <van-tabbar-item name="home" icon="home-o">首页</van-tabbar-item>
  5. <van-tabbar-item name="todo" icon="edit">待办</van-tabbar-item>
  6. <van-tabbar-item name="start" icon="guide-o">发起</van-tabbar-item>
  7. </van-tabbar>
  8. </div>
  9. </template>
  10. <script>
  11. import { mapStores } from 'pinia';
  12. import { tabStore } from '@/stores/tabStore';
  13. export default {
  14. props: {},
  15. data() {
  16. return {
  17. active: 'home',
  18. };
  19. },
  20. computed: {
  21. ...mapStores(tabStore),
  22. },
  23. created() {
  24. // 判断缓存中有没有存储激活的页面, 没有默认home
  25. if (this.tabStore.tabInfo) {
  26. this.active = this.tabStore.tabInfo;
  27. }
  28. },
  29. methods: {
  30. // 导航切换
  31. onChange() {
  32. console.log(this.active);
  33. this.tabStore.setTabInfo(this.active);
  34. switch (this.active) {
  35. case 'home':
  36. this.$router.push('/index/home/index');
  37. break;
  38. case 'todo':
  39. this.$router.push('/index/home/todo');
  40. break;
  41. case 'start':
  42. this.$router.push('/index/home/start');
  43. break;
  44. default:
  45. break;
  46. }
  47. },
  48. },
  49. };
  50. </script>