set-navigation-bar-title.uvue 1.8 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2 3 4 5 6 7 8 9
  <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11 12
  </view>
</template>

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

H
hdx 已提交
16 17 18 19 20 21
  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 已提交
22
    },
H
hdx 已提交
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
    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)
      }
63
    },
H
hdx 已提交
64
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
65
</script>