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

文章详细介绍了如何在uni-app项目中结合Vue3使用colorui框架,步骤包括下载colorui并导入项目,通过main.js注册cu-custom组件,然后在app.vue中获取系统信息以设置不同平台的导航栏高度,并在pages.json中取消原生导航栏,实现自定义导航栏效果。

步骤:

 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"
	}
}

 最后的结果:

        

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值