set-navigation-bar-title.uvue 1.2 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<template>
  <view>
    <page-head title="setNavigationBarTitle"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
      <button @tap="setNavigationBarTitle" class="uni-btn">
        设置当前页面的标题为 {{ newTitle }}
      </button>
    </view>
  </view>
</template>

<script lang="uts">
import { state, setLifeCycleNum } from '@/store/index.uts'

export default {
  data(){
    return {
      newTitle: 'new title'
    }
  },
  methods: {
    setNavigationBarTitle() {
      uni.setNavigationBarTitle({
        title: this.newTitle,
        success() {
          console.log('setNavigationBarTitle success')
          this.setLifeCycleNum(state.lifeCycleNum + 1)
        },
        fail() {
          console.log('setNavigationBarTitle success')
          this.setLifeCycleNum(state.lifeCycleNum - 1)
        },
        complete() {
          console.log('setNavigationBarTitle complete')
          this.setLifeCycleNum(state.lifeCycleNum + 1)
        }
      })
    },
    // 自动化测试
    getLifeCycleNum(): number {
      return state.lifeCycleNum
    },
    // 自动化测试
    setLifeCycleNum(num: number) {
      setLifeCycleNum(num)
    }
  },
}
</script>