set-navigation-bar-title.uvue 1.9 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4
<template>
  <view>
    <page-head title="setNavigationBarTitle"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
5 6 7 8 9
      <button @tap="setNavigationBarNewTitle" class="uni-btn">
        设置当前页面标题为: {{ newTitle }}
      </button>
      <button @tap="setNavigationBarLongTitle" class="uni-btn">
        设置超长标题
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11 12 13 14
      </button>
    </view>
  </view>
</template>

H
hdx 已提交
15 16
<script>
  import { state, setLifeCycleNum } from '@/store/index.uts'
DCloud-WZF's avatar
DCloud-WZF 已提交
17

H
hdx 已提交
18 19 20 21 22 23
  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'
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
24
    },
H
hdx 已提交
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
    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)
      }
65
    },
H
hdx 已提交
66
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
67
</script>