
简体中文
动态设置当前页面的标题
Web | 微信小程序 | Android | iOS | HarmonyOS |
---|---|---|---|---|
4.0 | 4.41 | 3.97 | 4.11 | 4.61 |
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | SetNavigationBarTitleOptions | 是 | - | - | |||||||||||||||||||||||||||||||
|
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errMsg | string | 是 | - | - |
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errCode | number | 是 | - | - | 设置导航栏标题错误码 - 4: 框架内部异常 |
errSubject | string | 是 | - | - | 统一错误主题(模块)名称 |
data | any | 否 | - | - | 错误信息中包含的数据 |
cause | Error | 否 | - | - | 源错误信息,可以包含多个错误,详见SourceError |
errMsg | string | 是 | - | - |
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errMsg | string | 是 | - | - |
类型 | 必备 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Promise<SetNavigationBarTitleSuccess> | 否 | ||||||||||||
|
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
示例
<template>
<page-head title="setNavigationBarTitle"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="setNavigationBarNewTitle" class="uni-btn">
设置当前页面标题为: {{ newTitle }}
</button>
<button @tap="setNavigationBarLongTitle" class="uni-btn">
设置超长标题
</button>
<!-- #ifdef APP-HARMONY -->
<button @tap="showNavigationBarLoading" class="uni-btn">
设置标题 loading
</button>
<button @tap="hideNavigationBarLoading" class="uni-btn">
隐藏标题 loading
</button>
<!-- #endif -->
</view>
</template>
<script>
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
return {
newTitle: 'new title',
longTitle: 'long title long title long title long title long title long title long title long title long title long title'
}
},
methods: {
// #ifdef APP-HARMONY
showNavigationBarLoading() {
uni.showNavigationBarLoading({
success: () => {
console.log('showNavigationBarLoading success')
},
fail: () => {
console.log('showNavigationBarLoading fail')
},
complete: () => {
console.log('showNavigationBarLoading complete')
}
})
},
hideNavigationBarLoading() {
uni.hideNavigationBarLoading({
success: () => {
console.log('hideNavigationBarLoading success')
},
fail: () => {
console.log('hideNavigationBarLoading fail')
},
complete: () => {
console.log('hideNavigationBarLoading complete')
}
})
},
// #endif
setNavigationBarNewTitle() {
uni.setNavigationBarTitle({
title: this.newTitle,
success: () => {
console.log('setNavigationBarTitle success')
this.setLifeCycleNum(state.lifeCycleNum + 1)
},
fail: () => {
console.log('setNavigationBarTitle fail')
this.setLifeCycleNum(state.lifeCycleNum - 1)
},
complete: () => {
console.log('setNavigationBarTitle complete')
this.setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
setNavigationBarLongTitle() {
uni.setNavigationBarTitle({
title: this.longTitle,
success() {
console.log('setNavigationBarTitle success')
},
fail() {
console.log('setNavigationBarTitle fail')
},
complete() {
console.log('setNavigationBarTitle complete')
}
})
},
// 自动化测试
getLifeCycleNum() : number {
return state.lifeCycleNum
},
// 自动化测试
setLifeCycleNum(num : number) {
setLifeCycleNum(num)
}
},
}
</script>
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errMsg | string | 是 | - | 错误信息 |