3.使用uView让tabbar更优雅

1. 使用uView让tabbar更优雅

1.1. 怎么才优雅?

为什么要做这个呢?起因还是因为我们自己做的tabbar都平平淡淡,没什么特色,然而,我们有时候看到有的小程序的tabbar,中间突出很大一块,是怎么做到的呢?

1.2. uView的tabbar合适吗?

  • tabbar底部导航栏:https://vkuviewdoc.fsq.pub/components/tabbar.html
  • 对应的demo:https://vkuviewdoc.fsq.pub/components/resource.html

动手下载运行起来看看效果:

效果还是非常好的,那就开始搞吧

1.3. 引入项目过程

1.3.1. 修改pages.json

主要就是改pages配置,把tabbar定义一下

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		// {
		// 	"path": "pages/index/index",
		// 	"style": {
		// 		"navigationBarTitleText": "uni-app"
		// 	}
		// }
		// uView的自定义tabbar demo
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "uView UI"
			}
		},
		{
			"path": "pages/js/index",
			"style": {
				"navigationBarTitleText": "工具"
			}
		},
		{
			"path": "pages/template/index",
			"style": {
				"navigationBarTitleText": "模板"
			}
		}
	],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	},
	"uniIdRouter": {},
	// uView的自定义tabbar demo,定义tabbar
	"tabBar": {
		"color": "#909399",
		"selectedColor": "#303133",
		"backgroundColor": "#FFFFFF",
		"borderStyle": "black",
		"list": [{
				"pagePath": "pages/index/index",
				"iconPath": "static/uview/example/component.png",
				"selectedIconPath": "static/uview/example/component_select.png",
				"text": "组件"
			},
			{
				"pagePath": "pages/js/index",
				"iconPath": "static/uview/example/js.png",
				"selectedIconPath": "static/uview/example/js_select.png",
				"text": "工具"
			},
			{
				"pagePath": "pages/template/index",
				"iconPath": "static/uview/example/template.png",
				"selectedIconPath": "static/uview/example/template_select.png",
				"text": "模板"
			}
		]
	}
}

1.3.2. 把demo里面的pages先拷贝过来

先拷贝,后面再删,主要是先运行起来。

其实也就是拷贝了3个文件,也没什么特别,好操作。

1.3.3. 引入tabbar的图片

同样,还是先拷贝过来,后面会改成我们自己的tabbar的图标。

把demo里的static/uview文件夹都拷贝过来。

1.3.4. 运行

就这么多,运行起来就是那样的效果:

1.4. 我们自己的项目适配

还是按照之前的套路:

  1. pages.json修改

    {
    	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
    		{
    			"path": "pages/bill_add/bill_add",
    			"style": {
    				"navigationBarTitleText": "记一笔"
    			}
    		},
    		{
    			"path": "pages/bill_list/bill_list",
    			"style": {
    				"navigationBarTitleText": "账单"
    			}
    		},
    		{
    			"path": "pages/bill_chat/bill_chat",
    			"style": {
    				"navigationBarTitleText": "图表"
    			}
    		},
    		{
    			"path": "pages/bill_detail/bill_detail",
    			"style": {
    				"navigationBarTitleText": "明细"
    			}
    		},
    		{
    			"path": "pages/my/my",
    			"style": {
    				"navigationBarTitleText": "我的"
    			}
    		}
    	],
    	"globalStyle": {
    		"navigationBarTextStyle": "black",
    		"navigationBarTitleText": "uni-app",
    		"navigationBarBackgroundColor": "#F8F8F8",
    		"backgroundColor": "#F8F8F8"
    	},
    	"uniIdRouter": {},
    	// uView的自定义tabbar demo,定义tabbar
    	"tabBar": {
    		"color": "#909399",
    		"selectedColor": "#303133",
    		"backgroundColor": "#FFFFFF",
    		"borderStyle": "black",
    		"list": [
    			{
    				"iconPath": "/static/tab-bar/账单.png",
    				"selectedIconPath": "/static/tab-bar/账单_h.png",
    				"text": "账单",
    				"pagePath": "pages/bill_list/bill_list"
    			},
    			{
    				"iconPath": "/static/tab-bar/图表.png",
    				"selectedIconPath": "/static/tab-bar/图表_h.png",
    				"text": "图表",
    				"pagePath": "pages/bill_chat/bill_chat"
    			},
    			{
    				"iconPath": "/static/tab-bar/记账.png",
    				"selectedIconPath": "/static/tab-bar/记账_h.png",
    				"text": "记账",
    				"pagePath": "pages/bill_add/bill_add"
    			},
    			{
    				"iconPath": "/static/tab-bar/明细.png",
    				"selectedIconPath": "/static/tab-bar/明细_h.png",
    				"text": "账单",
    				"pagePath": "pages/bill_detail/bill_detail"
    			},
    			{
    				"iconPath": "/static/tab-bar/我的.png",
    				"selectedIconPath": "/static/tab-bar/我的_h.png",
    				"text": "我的",
    				"pagePath": "pages/my/my"
    			}
    		]
    	}
    }
    
  2. 写对应的pages vue文件

  3. 引入图标的png图片

  4. 最后的结果就是

相关推荐

  1. uView Tabbar 底部导航栏

    2024-05-14 08:36:08       44 阅读
  2. php开发优雅-ThinkPHP篇

    2024-05-14 08:36:08       15 阅读
  3. 8招Python代码优雅

    2024-05-14 08:36:08       9 阅读
  4. Sass 使用指南: CSS 编程高效、强大

    2024-05-14 08:36:08       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-14 08:36:08       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-14 08:36:08       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-14 08:36:08       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-14 08:36:08       20 阅读

热门阅读

  1. RSA非对称加密解密,前端公钥加密后端私钥解密

    2024-05-14 08:36:08       11 阅读
  2. Spring Cloud 架构技术版本选型

    2024-05-14 08:36:08       15 阅读
  3. 优化运行效率

    2024-05-14 08:36:08       11 阅读
  4. Git检测和处理版本冲突的原理

    2024-05-14 08:36:08       12 阅读
  5. Linux 里的tmp目录

    2024-05-14 08:36:08       13 阅读
  6. echo服务器--聊天版

    2024-05-14 08:36:08       11 阅读
  7. vue项目中vue.config.js中配置webpack详解

    2024-05-14 08:36:08       13 阅读
  8. web安全学习笔记(14)

    2024-05-14 08:36:08       12 阅读
  9. 威胁建模的艺术:了解网络安全风险的另一面

    2024-05-14 08:36:08       14 阅读