bottomNav.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="bottom">
  3. <!-- <van-row class="test-row">
  4. <van-col span="8">
  5. <div
  6. class="item"
  7. @click="clickItem('/')"
  8. :class="{ active: $route.path === '/' }"
  9. >
  10. <i class="iconA" :class="{ iconC: $route.path === '/' }"></i>
  11. <p>首页</p>
  12. </div>
  13. </van-col>
  14. <van-col span="8">
  15. <div
  16. class="item"
  17. @click="clickItem('/learning')"
  18. :class="{ active: $route.path === '/learning' }"
  19. >
  20. <i class="iconA" :class="{ iconC: $route.path === '/learning' }"></i>
  21. <p>学习中心</p>
  22. </div>
  23. </van-col>
  24. <van-col span="8">
  25. <div
  26. class="item"
  27. @click="clickItem('/my')"
  28. :class="{ active: $route.path === '/my' }"
  29. >
  30. <i class="iconA" :class="{ iconC: $route.path === '/my' }"></i>
  31. <p>我的</p>
  32. </div>
  33. </van-col>
  34. </van-row> -->
  35. <!-- @change="onChange" -->
  36. <van-tabbar v-model="active" active-color="#46bb65" inactive-color="#000">
  37. <van-tabbar-item to="/">
  38. <span>首页</span>
  39. <template #icon="props">
  40. <img :src="props.active ? home.active : home.inactive" />
  41. </template>
  42. </van-tabbar-item>
  43. <van-tabbar-item to="/learning">
  44. <span>学习中心</span>
  45. <template #icon="props">
  46. <img :src="props.active ? learning.active : learning.inactive" />
  47. </template>
  48. </van-tabbar-item>
  49. <van-tabbar-item to="/find">
  50. <span>发现</span>
  51. <template #icon="props">
  52. <img :src="props.active ? find.active : find.inactive" />
  53. </template>
  54. </van-tabbar-item>
  55. <van-tabbar-item to="/my">
  56. <span>我的</span>
  57. <template #icon="props">
  58. <div class="noticeBox">
  59. <span v-if="nCount != 0"></span>
  60. <img :src="props.active ? my.active : my.inactive" />
  61. </div>
  62. </template>
  63. </van-tabbar-item>
  64. <!-- <van-tabbar-item badge="4">
  65. <span>自定义</span>
  66. <template #icon="props">
  67. <img :src="props.active ? ccc.active : ccc.inactive" />
  68. </template>
  69. </van-tabbar-item> -->
  70. </van-tabbar>
  71. </div>
  72. </template>
  73. <script>
  74. import home from "../../assets/tabbarIcon/shouye1.png";
  75. import home_active from "../../assets/tabbarIcon/shouye.png";
  76. import learning from "../../assets/tabbarIcon/xuexizhongxin1.png";
  77. import learning_active from "../../assets/tabbarIcon/xuexizhongxin.png";
  78. import find from "../../assets/tabbarIcon/faxian1.png";
  79. import find_active from "../../assets/tabbarIcon/faxian.png";
  80. import my from "../../assets/tabbarIcon/wode1.png";
  81. import my_active from "../../assets/tabbarIcon/wode.png";
  82. export default {
  83. props: {
  84. luyou: Number,
  85. nCount: Number,
  86. },
  87. data() {
  88. return {
  89. active: 0,
  90. navTabs: ["/", "/learning", "/find", "/my"], // 底部导航
  91. home: {
  92. active: home_active,
  93. inactive: home,
  94. },
  95. learning: {
  96. active: learning_active,
  97. inactive: learning,
  98. },
  99. find: {
  100. active: find_active,
  101. inactive: find,
  102. },
  103. my: {
  104. active: my_active,
  105. inactive: my,
  106. },
  107. };
  108. },
  109. created() {
  110. this.routerP();
  111. },
  112. methods: {
  113. routerP() {
  114. const { navTabs } = this.$data;
  115. let router_path = this.$route.path;
  116. console.log(router_path);
  117. for (var i = 0; i < navTabs.length; i++) {
  118. if (router_path == navTabs[i]) {
  119. this.active = i;
  120. break;
  121. }
  122. }
  123. },
  124. clickItem: function (path) {
  125. this.$router.push(path);
  126. },
  127. // onChange(index) {
  128. // Notify({ type: 'primary', message: index });
  129. // },
  130. },
  131. watch: {
  132. luyou: {
  133. handler(n, o) {
  134. this.routerP();
  135. },
  136. deep: true, // 深度监听父组件传过来对象变化
  137. },
  138. },
  139. };
  140. </script>
  141. <style scoped>
  142. .bottom {
  143. }
  144. .active {
  145. color: #108b70;
  146. }
  147. .noticeBox {
  148. position: relative;
  149. /* margin-right: 10px; */
  150. }
  151. .noticeBox span {
  152. position: absolute;
  153. background: red;
  154. width: 5px;
  155. height: 5px;
  156. border-radius: 30px;
  157. top: -3px;
  158. right: -3px;
  159. }
  160. </style>