set-navigation-bar-title.uvue 1.9 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
<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>
  </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: {
      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)
      }
    },
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
65
</script>