123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <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>
|