uniapp 原生导航栏动态修改标题 添加右侧文字按钮

有时候登录和注册页面样式差不多相同的, 这时我们就可以使用一个页面写登录和注册功能,如果想实现动态导航栏就可以使用uni.setNavigationBarTitle来动态修改导航栏的文字

代码示例

<template>
  <view class="content">
		<button @click="router(1)">登录</button>
		<button @click="router(2)">注册</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      
    };
  },
  methods: {
	router(e) {
		uni.navigateTo({
			url: '../index/index?id=' + e
		})
	}
  },
};
</script>
<template>
  <view class="box"> 111 </view>
</template>

<script>
export default {
  data() {
    return {};
  },
  onLoad(e) {
    console.log(e);
    // 动态设置导航栏文字
    uni.setNavigationBarTitle({
      title: e.id === "1" ? "登录" : "注册",
    });
  },
};
</script>

导航栏右侧添加文字 点击事件

{
      "path": "pages/username/username",
      "style": {
        "navigationBarTitleText": "修改昵称",
        "app-plus": {
          "titleNView": {
            "buttons": [
              {
                "color": "#000",
                "fontSize": "28rpx",
                "text": "保存"
              }
            ]
          }
        }
      }
    }
<template>
  <view class="box"> 111 </view>
</template>

<script>
export default {
  data() {
    return {};
  },
  // 按钮监听函数
  onNavigationBarButtonTap() {
    console.log("我是导航栏右侧的文字");
  },
};
</script>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值