uniapp自定义头部导航

uniapp自定义头部导航

javascript 复制代码
<template>
	<view>
		<view class="dynamic" :style="{'border-bottom':borderBottom}">
			<view :style="{'width':'100%','height':statusBarHeight+'px','background-color':backgourndColor}"></view>
			<view class="dynamicBox" :style="{'background-color':backgourndColor,'height':'80rpx','width':'100%'}">
				<view :style="{'width': bothSidesWidth,'height': '100%','display': 'flex','align-items': 'center'}" v-if="pattern!='normal'">
					<image src="/static/image/whiteBack.png" @tap="goback" style="width: 44rpx;height: 44rpx;"></image>
				</view>
				<image src="/static/image/whiteBack.png" v-if="pattern=='normal'" @tap="goback" style="width: 44rpx;height: 44rpx;"></image>
				<view class="navtitle" :style="{'color':fontColor,'font-size':fontSize,'font-weight':fontWeight}">{{title}}</view>
				<view :style="{'width': bothSidesWidth,'height':'100%'}" v-if="pattern!='normal'">
					<slot></slot>
				</view>
				<view style="width: 44rpx;height:100%;" v-if="pattern=='normal'"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				statusBarHeight:getApp().globalData.mySystemInfo.statusBarHeight,//状态栏高度
			}
		},
		props:{
			//名称
			title:{
				type:String,
				default:'详情'
			},
			//右侧是否显示
			pattern:{
				type:String,
				default:'normal'
			},
			//背景颜色
			backgourndColor:{
				type:String,
				default:'#ffc526'
			},
			//文字颜色
			fontColor:{
				type:String,
				default:'#fff'
			},
			//两侧宽度
			bothSidesWidth:{
				type:String,
				default:'130rpx'
			},
			//下边框
			borderBottom:{
				type:String,
				default:'none'
			},
			//返回按钮形式
			backType:{
				type:String,
				default:'normal'
			},
			//文字大小
			fontSize:{
				type:String,
				default:'34rpx'
			},
			//文字加粗
			fontWeight:{
				type:Number,
				default:600
			}
		},
		methods:{
			//返回
			goback(e){
				if(this.backType == 'normal'){
					uni.navigateBack()
				}else{
					this.$emit('backOperation')
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.dynamic{
		width: 100%;		
		.dynamicBox{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20rpx;
			box-sizing: border-box;
			font-size: 0;
			.navtitle{
				max-width: 500rpx;
				white-space: nowrap;
				overflow: hidden;
			}
		}
	}
</style>
相关推荐
前端snow6 小时前
ai agent --- postgreSQL 关系型数据库
前端
卷无止境7 小时前
ECharts:把数据变成故事的可视化利器
前端
Eric_见嘉7 小时前
在职前端 Skill 和 MCP 分享
前端·后端·agent
liangshanbo12157 小时前
面试题:如何优化 Webpack 的打包速度?
前端·webpack·node.js
wengad7 小时前
从 wangEditor 迁到 wangEditor-next
前端·javascript·vue.js
行者-全栈开发8 小时前
【前端/JS框架】CVE-2026-3854:GitHub Enterprise Server X-Stat注入XSS漏洞深度剖析与紧急修复指南
前端·javascript·github
计算机魔术师9 小时前
AMD砸82亿买下李飞飞,这次不卖芯片卖什么?
前端
hzxpaipai10 小时前
杭州企业官网怎么建设?从策划到上线的5步建站方法
运维·服务器·前端·网络
怕浪猫10 小时前
2026年金九银十,我面了22个前端
前端·javascript·面试
IT_陈寒10 小时前
Vue 这个响应式陷阱,我的头发都掉没了
前端·人工智能·后端