Navbar.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="NavBar" id="NavBar">
  3. <van-tabbar v-model="tabbarTempValue" @change="onChange" >
  4. <van-tabbar-item icon="wap-home">首页</van-tabbar-item>
  5. <van-tabbar-item icon="comment">工作台</van-tabbar-item>
  6. <van-tabbar-item icon="manager">个人中心</van-tabbar-item>
  7. </van-tabbar>
  8. <router-view></router-view>
  9. <!-- <router-view />
  10. <van-tabbar v-model="tabbarTempValue">
  11. <van-tabbar-item
  12. v-for="(item,index) in tabbars"
  13. :key="index"
  14. :to="(item.name)"
  15. >
  16. <span>{{item.title}}</span>
  17. <img
  18. slot="icon"
  19. slot-scope="props"
  20. :src="props.active ? item.active : item.normal"
  21. />
  22. </van-tabbar-item>
  23. </van-tabbar> -->
  24. </div>
  25. </template>
  26. <script>
  27. import Vue from 'vue';
  28. import VueRouter from 'vue-router';
  29. export default {
  30. props: {
  31. active: Number
  32. },
  33. name:'NavBar',
  34. data() {
  35. return {
  36. imgUrl:'',
  37. tabbarTempValue: this.active,
  38. tabbars: [
  39. {
  40. name: "/",
  41. title: "首页",
  42. normal: "http://test2.h-etrip.com/app/assets/img/TabsHome.png",
  43. active: "../../assets/img/icon_tab_hp_selected.png"
  44. },
  45. {
  46. name: "/workbench",
  47. title: "工作台",
  48. normal: "http://test2.h-etrip.com/app/assets/img/TabsTravel.png",
  49. active: "http://test2.h-etrip.com/app/assets/img/TabsTravelFocus.png"
  50. },
  51. {
  52. name: "/user",
  53. title: "我的",
  54. normal: "http://test2.h-etrip.com/app/assets/img/TabsFace.png",
  55. active: "http://test2.h-etrip.com/app/assets/img/TabsFaceFocus.png"
  56. }
  57. ]
  58. }
  59. },
  60. created() {
  61. //由于 vant 标签栏路由模式,无法自动加载页面,所以这里需要初始化
  62. console.log(this.$route);//打印当前路由属性
  63. // if (this.$route.path === '/') {
  64. // this.$router.push('/home');
  65. // }
  66. },
  67. methods:{
  68. async NavInit() {
  69. if(localStorage.getItem('token')){
  70. const res = await this.$http.get('/user/' + localStorage.getItem('id'))
  71. this.imgUrl = res.data[0].user_img
  72. }
  73. },
  74. onChange(index){
  75. console.log(index)
  76. this.tabbarTempValue = 0
  77. // this.active = index
  78. // console.log(this.tabbarTempValue)
  79. if(index == 0){
  80. this.$router.push("/home");
  81. }else if(index == 1){
  82. this.$router.push("/workbench");
  83. }else{
  84. this.$router.push("/user");
  85. }
  86. }
  87. },
  88. mounted() {
  89. // this.NavInit()
  90. }
  91. }
  92. </script>
  93. <style scoped lang="less">
  94. .NavBar{
  95. }
  96. </style>