uniapp自定义顶部导航栏大小
时间: 2023-05-26 16:02:40 浏览: 110
若需要在uniapp中自定义顶部导航栏的大小,可以通过修改页面的样式来实现。
1. 在对应页面的 `style` 中添加以下样式:
```css
/* 设置导航栏高度为60px(根据实际需要修改) */
.uni-bar {
height: 60px;
}
/* 设置左侧返回按钮的大小(可选) */
.uni-icon-back {
width: 24px;
height: 24px;
}
```
2. 在模板中添加自定义导航栏组件,设置导航栏高度和返回按钮大小:
```html
<template>
<view class="navigation">
<view class="uni-bar">
<view class="uni-icon-back"></view>
<view class="title">{{title}}</view>
</view>
</view>
</template>
<script>
export default {
props: {
title: {
type: String,
default: ''
}
}
}
</script>
<style>
.navigation {
height: 60px;
width: 100%;
}
.uni-bar {
height: 60px;
background: #fff;
display: flex;
justify-content: flex-start;
align-items: center;
padding-left: 20px; /* 修改左右边距根据实际需要 */
padding-right: 20px;
border-bottom: 1px solid #e5e5e5;
}
.uni-icon-back {
width: 24px;
height: 24px;
background: url("/static/返回按钮.png"); /* 修改返回按钮图片根据实际需要 */
background-size: contain;
}
.title {
font-size: 18px;
font-weight: bold;
color: #333;
margin-left: 20px;
}
</style>
```
3. 在业务页面中引用自定义导航栏组件,并传入标题参数:
```html
<template>
<view>
<custom-navigation title="自定义导航栏"></custom-navigation>
<!-- 页面内容 -->
</view>
</template>
<script>
import CustomNavigation from '@/components/CustomNavigation.vue'
export default {
components: {
CustomNavigation
}
}
</script>
```