当前位置: 首页 > news >正文

uniapp自定义Tabbar教程

uniapp自定义Tabbar

1、定义tabbar

在pages.json中配置除主要页面地址,

	"tabBar": {"custom": true,"list": [{"pagePath": "pages/home/index"},{"pagePath": "pages/user-center/index"}]},

2、创建自定义Tabbar组件

<template><up-tabbar :value="selected" @change="handleChange" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true"><up-tabbar-item v-for="item in tabbarList" :key="item.text" :text="item.text" :icon="item.icon" /></up-tabbar>
</template><script setup lang="ts">import { reactive, ref } from 'vue'const props = defineProps({selected: {// 当前选中的tab indextype: Number,default: 1,},});const tabbarList = reactive([{text: "首页",icon: "home",pagePath: "/pages/home/index"},{text: "我的",icon: "account",pagePath: "/pages/user-center/index"}])function handleChange(index) {console.log('tab ' + index)const tarbar = tabbarList[index]// 跳转到其他页面uni.switchTab({url: tarbar.pagePath})}
</script><style scoped lang="scss">
</style>

3、在以上定义的主页面中加入以下的代码,每个页面都要加

<template>// ........// 这里的selected很重要,标识这里是第一个页面,如果是第二个 这里就是2<MyTabbarVue :selected="1" />
</template><script setup lang="ts">import { onShow } from '@dcloudio/uni-app';import MyTabbarVue from '../../components/MyTabbar.vue';// 这里主要是为了无感隐藏原来的tabbaronShow(() => {uni.hideTabBar({animation: false})})
</script>

http://www.mrgr.cn/news/33727.html

相关文章:

  • [Redis] 渐进式遍历+使用jedis操作Redis+使用Spring操作Redis
  • 【机器学习】12-决策树1——概念、特征选择
  • 内网穿透out了?黑群晖+IPv6+NAS公网助手的访问体验
  • 强大的重命名工具 | Bulk Rename Utility v4.0 便携版
  • Integer 源码记录
  • Web Components之继承
  • K8s容器运行时,移除Dockershim后存在哪些疑惑?
  • 局部凸空间及其在算子空间中的应用之四——归纳极限空间2
  • MATLAB中多张fig图合并为一个图
  • 如何使用数字人直播?
  • 深度学习03-神经网络01-什么是神经网络?
  • 算法之逻辑斯蒂回归(Logistic regression)
  • Maven-一、分模块开发
  • Excel常见操作命令~你值得拥有!
  • 没错,我给androidx修了一个bug!
  • 认识结构体
  • 鸿蒙开发(NEXT/API 12)【跨设备互通NDK开发】协同服务
  • 【机器学习】13-决策树2——决策树生成、剪枝
  • SystemExit: 系统退出异常的完美解决方法⚙️
  • 从示例的角度介绍async copy,剖析一个 cuda sample case Samples/3/tf32TensorCoreGemm