custom-tabbar.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view class="ezy-custom-tabbar">
  3. <view class="tabbar-item-box">
  4. <view class="tabbar-item" v-for="(item, index) in tabList" :key="index" @click="switchTab(item.path)"
  5. :style="{backgroundImage: 'url(' + item.iconPath + ')'}"></view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. data() {
  12. return {
  13. tabList: [
  14. {iconPath: 'static/images/tabbar/unselect/plan-sj.png',path:'/pages/study/index' },
  15. {iconPath: 'static/images/tabbar/unselect/develop-sj.png',path:'/pages/study/index' },
  16. {iconPath: 'static/images/tabbar/unselect/partner-sj.png',path:'/pages/study/index' },
  17. {iconPath: 'static/images/tabbar/unselect/my-sj.png',path:'/pages/my/index' },
  18. // 更多 Tab 项...
  19. ]
  20. };
  21. },
  22. methods: {
  23. switchTab(path, params = {}) {
  24. // 将参数拼接到路径中
  25. let queryString = Object.keys(params).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&');
  26. if (queryString) {
  27. path += `?${queryString}`;
  28. }
  29. uni.navigateTo({
  30. url: path
  31. });
  32. // 使用 uni.switchTab 进行跳转(适用于 tabBar 页面)
  33. // if (this.isTabBarPage(path)) {
  34. // uni.switchTab({
  35. // url: path
  36. // });
  37. // } else {
  38. // // 使用 uni.navigateTo 进行跳转(适用于非 tabBar 页面)
  39. // uni.navigateTo({
  40. // url: path
  41. // });
  42. // }
  43. },
  44. isTabBarPage(path) {
  45. // 根据你的 tabBar 页面路径进行判断
  46. const tabBarPages = ['/pages/study/index', '/pages/study/index','/pages/study/index','/pages/my/index'];
  47. return tabBarPages.includes(path);
  48. }
  49. }
  50. }
  51. </script>
  52. <style scoped>
  53. .custom-tabbar {
  54. display: flex;
  55. justify-content: space-around;
  56. align-items: center;
  57. /* 其他样式 */
  58. }
  59. .tab-item {
  60. flex: 1;
  61. /* 样式 */
  62. }
  63. .tab-icon {
  64. /* 图标样式 */
  65. }
  66. </style>