uniapp的vue3版本使用colorUI的自定义导航栏

步骤:

 1.下载colorui,将colorui文件导入项目根目录

2.main.js 引入cu-custom组件全局使用


import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  //  vue3使用app.component 注册为全局组件
  app.component('cu-custom',cuCustom)
  
  return {
    app
  }
}

 3.app.vue 获取系统信息,设置导航栏高度

<script lang="ts" setup>

	import { getCurrentInstance } from 'vue'
		
  onLaunch(() => {
    
	
	//导航栏高度
	uni.getSystemInfo({
	        success: function(e) {
			// 获取 appContext  上下文
			const {appContext} = getCurrentInstance()
			console.log('StatusBar',appContext)
			// #ifndef MP
			appContext.config.globalProperties.StatusBar = e.statusBarHeight;
			if (e.platform == 'android') {
				appContext.config.globalProperties.CustomBar = e.statusBarHeight + 50;
				} else {
				appContext.config.globalProperties.CustomBar = e.statusBarHeight + 45;
			};
			// #endif
			// #ifdef MP-WEIXIN
			appContext.config.globalProperties.StatusBar = e.statusBarHeight;
			let custom = wx.getMenuButtonBoundingClientRect();
			appContext.config.globalProperties.Custom = custom;
			appContext.config.globalProperties.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
			 // #endif        
			// #ifdef MP-ALIPAY
			appContext.config.globalProperties.StatusBar = e.statusBarHeight;
			appContext.config.globalProperties.CustomBar = e.statusBarHeight + e.titleBarHeight;
			 // #endif
	        }
	    })
	
  })
  onShow(() => {
    console.log('App Show-->')
  })
  onHide(() => {
    console.log('App Hide --')
  })
</script>

4.pages,json 取消原生导航栏

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
			     // 原生导航的文字
				"navigationBarTitleText": "uni-app"
			}
		}
	    ,{
            "path" : "pages/my/my",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "my",
                "enablePullDownRefresh": false
            }
            
        }
    ],
	"tabBar": {
		"color": "#999999",
		"selectedColor": "#222222",
		"borderStyle": "black",
		"backgroundColor": "#ffffff",
		"list": [{
				"pagePath": "pages/index/index",
				// "iconPath": "static/icon/index.png",
				// "selectedIconPath": "static/icon/index_active.png",
				"text": "首页"
			},
			{
				"pagePath": "pages/my/my",
				// "iconPath": "static/icon/my.png",
				// "selectedIconPath": "static/icon/my_active.png",
				"text": "我的"
			}
		]
	},
	"globalStyle": {
	    // "navigationStyle": "custom", 取消原生导航
		"navigationStyle": "custom",
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
}

 最后的结果:

        

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3 和 UniApp 中,可以使用定义导航来实现个性化的导航样式和功能。下面是一种实现方式: 1. 在 App.vue 文件中,可以设置全局的导航样式和功能。你可以在顶部放置一个自定义导航组件,并设置相应的样式和事件。例如: ```vue <template> <div> <!-- 自定义导航 --> <custom-navbar></custom-navbar> <!-- 页面内容 --> <router-view></router-view> </div> </template> <script> import CustomNavbar from '@/components/CustomNavbar.vue'; export default { components: { CustomNavbar, }, }; </script> ``` 2. 创建一个 CustomNavbar.vue 组件,并在其中定义导航的样式和事件。例如: ```vue <template> <nav class="custom-navbar"> <div class="left"> <!-- 左侧按钮 --> </div> <div class="title"> <!-- 标题 --> </div> <div class="right"> <!-- 右侧按钮 --> </div> </nav> </template> <script> export default { methods: { // 左侧按钮点击事件 handleLeftClick() { // 处理左侧按钮点击事件 }, // 右侧按钮点击事件 handleRightClick() { // 处理右侧按钮点击事件 }, }, }; </script> <style scoped> .custom-navbar { /* 导航样式 */ } .left, .right { /* 左侧和右侧按钮样式 */ } .title { /* 标题样式 */ } </style> ``` 3. 在需要自定义导航的页面中,可以通过导入 CustomNavbar 组件来替换全局的导航。例如: ```vue <template> <div> <!-- 自定义导航 --> <custom-navbar></custom-navbar> <!-- 页面内容 --> <!-- ... --> </div> </template> <script> import CustomNavbar from '@/components/CustomNavbar.vue'; export default { components: { CustomNavbar, }, }; </script> ``` 通过以上步骤,你可以在 Vue3 和 UniApp 中实现自定义导航。你可以根据需要自定义导航的样式和功能,来满足不同的设计需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值