uniapp中动态修改导航栏标题

使用场景:从A页面跳转至B页面,在A页面有多种消息类型,跳转B页面则显示不同的导航栏标题,如视频所示:

A页面代码如下:

onClick(type) {
	uni.navigateTo({
		url: `./messageDetails?type=` + type
	})
},

B页面代码如下:

<template>
	<view class="container">
		<text>{{text}}</text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				text: ''
			}
		},
		onLoad(options) {
			if (options.type == 1) {
				this.text = '消息通知'
				uni.setNavigationBarTitle({
					title: '消息通知'
				});
			} else if (options.type == 2) {
				this.text = '互动消息'
				uni.setNavigationBarTitle({
					title: '互动消息'
				});
			} else if (options.type == 3) {
				this.text = '系统消息'
				uni.setNavigationBarTitle({
					title: '系统消息'
				});
			} else if (options.type == 4) {
				this.text = '其他'
				uni.setNavigationBarTitle({
					title: '其他'
				});
			}
		},
		methods: {}
	}
</script>

<style lang="scss">
	.container {
		padding: 0;
		margin: 0;
	}
</style>

Who we were does not dictate who we will be

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐