uniapp微信小程序自定义导航栏

效果如下:

重点在于pages.json文件里的这个配置开启自定义导航栏:"navigationStyle": "custom",

	"pages": [
		{
			"path" : "pages/index/index",
			"style" : 
			{
				"navigationStyle": "custom",
				"enablePullDownRefresh": true,
				"navigationBarBackgroundColor": "#fff", // 顶部背景颜色
				"onReachBottomDistance": 100
			}
		},
    ]

navbar组件

<template>
	<view style="position: sticky;top: 0;background-color: #fff;z-index:10;">
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="cuIcon-back"></text>
					<slot name="backText"></slot>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar = this.StatusBar;
				// var CustomBar = this.CustomBar;
				var CustomBar = 0;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>

页面中引用组件

<template>
	<view class="box">
		<Navbar class="navBox" bgColor="bg-gradual-blue" :isBack="false">
			<view class="tab" slot="content">
				<view @click="change(0)" :style="{'background-color':!active ?'#1989fa':'#fff','color':!active ? '#fff':'#1989fa'}" class="tabItem">
					<van-icon name="clock-o" style="margin-right: 10px;"/>待报价
				</view>
				<view @click="change(1)" :style="{'color':!active ? '#1989fa':'#fff','background-color':!active ? '#fff':'#1989fa'}" class="tabItem">
					<van-icon name="todo-list-o" style="margin-right: 10px;"/>历史
				</view>
			</view>
		</Navbar>
		<AgentList @handle="handle"  ref="agentList" @toast="toast" v-show="!active"/>
		<AllList  @handle="handle"   ref="allList" @toast="toast" v-show="active"/>
		<van-toast id="van-toast" />
		<van-tabbar active="{{ tabbarActive }}" @change="onChange" style="z-index: 60;">
		  <van-tabbar-item icon="orders-o">业务入口</van-tabbar-item>
		  <van-tabbar-item icon="manager-o">用户中心</van-tabbar-item>
		</van-tabbar>
	</view>
</template>

		change(event){
			this.active = event
			if(uni.getStorageSync("allListRefresh")&&this.active){
				this.$refs.allList.getList();
				uni.removeStorageSync("allListRefresh")
			}
		},

<style lang="less">
.tab{
	width: 220px;
	padding: 7px 0;
	display: flex;
	text-align: center;
	margin:0 10px;
	font-size: 14px;
	.tabItem{
		flex: 1;
		border-radius: 20px;
		padding: 2px;
		line-height: 24px;
		border: 1px #1989fa solid;
		margin-right: 5px;
	}
}
</style>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值