二uniapp的首页认识

首页

我们进入uniapp,首先肯定要先进去首页,那么怎么设置本平台的首页呢,看过上一篇文章的童鞋们都晓得每个文件夹里的含义,这里再截图说下
在这里插入图片描述
聪明的童鞋可能都猜到了 我们要进入页面的配置信息(pages.json)中

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "uni-app"
			}
		}
	],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
}

这里pages是一个数组,数组中包含的对象就是每一个页面,默认第一项是应用启动页,我们只需要将首页放在该数组的第一项即可。

  1. path:页面启动的路径,我们这里是pages/index/index,要养成良好的规范,所有的页面都放在pages中
  2. style:页面的配置信息,里面包含页面的标题、颜色、背景色以及是否可下拉刷新等等功能。Hbuilder有自动提示功能,小伙伴可以都尝试下。
    具体文档地址:
    https://uniapp.dcloud.io/collocation/pages?id=style

除了每个页面的“pages”属性,还有globalStyle属性,这个属性代表着全部页面的style,若在pages的数组中没有设置单独的样式,则自动使用全部style里的属性。

"globalStyle": {
		"navigationBarTextStyle":"white",
		"navigationBarTitleText": "测试内容",
		"navigationBarBackgroundColor": "#51CC62",
		"backgroundColor": "#51CC62"
	}

结果如下:
在这里插入图片描述
解析:因为我们在pages中的style属性里也设置里标题,所以自动使用子类的标题,下面我们将子类的标题删除,再测试一下:
代码:

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				//"navigationBarTitleText": "uni-app"
			}
		}
	],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app测试",
		"navigationBarBackgroundColor": "#55aa7f",
		"backgroundColor": "#F8F8F8"
	}
}

保存后自动编译
结果如下:
在这里插入图片描述
解析:因为页面我们没有设置,所以自动使用全局配置

下一节 tabBar组件

UniApp是一个基于Vue.js的跨平台开发框架,可以用于开发iOS、Android、H5等多个平台的应用。在UniApp中,主页布局可以通过使用Vue组件和样式来实现。 一种常见的UniApp主页布局方式是使用底部导航栏,可以在页面底部放置多个导航按钮,每个按钮对应一个页面。用户点击不同的按钮时,UniApp会自动切换到对应的页面。 以下是一个简单的UniApp主页布局示例: 1. 创建一个底部导航栏组件(BottomTabBar.vue): ```html <template> <view class="tab-bar"> <view class="tab-item" @click="switchTab(0)"> <text>首页</text> </view> <view class="tab-item" @click="switchTab(1)"> <text>消息</text> </view> <view class="tab-item" @click="switchTab(2)"> <text>我的</text> </view> </view> </template> <script> export default { methods: { switchTab(index) { uni.switchTab({ url: this.tabList[index].pagePath }); } } } </script> <style> .tab-bar { display: flex; justify-content: space-around; align-items: center; height: 50px; background-color: #f5f5f5; } .tab-item { flex: 1; display: flex; justify-content: center; align-items: center; } </style> ``` 2. 在App.vue中引入底部导航栏组件,并配置页面路由: ```html <template> <view> <router-view></router-view> <bottom-tab-bar></bottom-tab-bar> </view> </template> <script> import BottomTabBar from '@/components/BottomTabBar.vue'; export default { components: { BottomTabBar } } </script> <style> /* 全局样式 */ </style> ``` 3. 在pages文件夹下创建三个页面组件(Home.vue、Message.vue、Mine.vue),并配置页面路由: ```html <template> <view> <!-- 页面内容 --> </view> </template> <script> export default { // 页面逻辑 } </script> <style> /* 页面样式 */ </style> ``` 通过以上步骤,你可以实现一个简单的UniApp主页布局。当用户点击底部导航栏的按钮时,UniApp会自动切换到对应的页面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值