custom-tabbar.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.switchTab 进行跳转(适用于 tabBar 页面)
  30. if (this.isTabBarPage(path)) {
  31. uni.switchTab({
  32. url: path
  33. });
  34. } else {
  35. // 使用 uni.navigateTo 进行跳转(适用于非 tabBar 页面)
  36. uni.navigateTo({
  37. url: path
  38. });
  39. }
  40. },
  41. isTabBarPage(path) {
  42. // 根据你的 tabBar 页面路径进行判断
  43. const tabBarPages = ['/pages/study/index', '/pages/study/index','/pages/study/index','/pages/my/index'];
  44. return tabBarPages.includes(path);
  45. }
  46. }
  47. }
  48. </script>
  49. <style scoped>
  50. .custom-tabbar {
  51. display: flex;
  52. justify-content: space-around;
  53. align-items: center;
  54. /* 其他样式 */
  55. }
  56. .tab-item {
  57. flex: 1;
  58. /* 样式 */
  59. }
  60. .tab-icon {
  61. /* 图标样式 */
  62. }
  63. </style>