set-navigation-bar-title.uvue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <page-head title="setNavigationBarTitle"></page-head>
  3. <view class="uni-padding-wrap uni-common-mt">
  4. <button @tap="setNavigationBarNewTitle" class="uni-btn">
  5. 设置当前页面标题为: {{ newTitle }}
  6. </button>
  7. <button @tap="setNavigationBarLongTitle" class="uni-btn">
  8. 设置超长标题
  9. </button>
  10. <!-- #ifdef APP-HARMONY -->
  11. <button @tap="showNavigationBarLoading" class="uni-btn">
  12. 设置标题 loading
  13. </button>
  14. <button @tap="hideNavigationBarLoading" class="uni-btn">
  15. 隐藏标题 loading
  16. </button>
  17. <!-- #endif -->
  18. </view>
  19. </template>
  20. <script>
  21. import { state, setLifeCycleNum } from '@/store/index.uts'
  22. export default {
  23. data() {
  24. return {
  25. newTitle: 'new title',
  26. longTitle: 'long title long title long title long title long title long title long title long title long title long title'
  27. }
  28. },
  29. methods: {
  30. // #ifdef APP-HARMONY
  31. showNavigationBarLoading() {
  32. uni.showNavigationBarLoading({
  33. success: () => {
  34. console.log('showNavigationBarLoading success')
  35. },
  36. fail: () => {
  37. console.log('showNavigationBarLoading fail')
  38. },
  39. complete: () => {
  40. console.log('showNavigationBarLoading complete')
  41. }
  42. })
  43. },
  44. hideNavigationBarLoading() {
  45. uni.hideNavigationBarLoading({
  46. success: () => {
  47. console.log('hideNavigationBarLoading success')
  48. },
  49. fail: () => {
  50. console.log('hideNavigationBarLoading fail')
  51. },
  52. complete: () => {
  53. console.log('hideNavigationBarLoading complete')
  54. }
  55. })
  56. },
  57. // #endif
  58. setNavigationBarNewTitle() {
  59. uni.setNavigationBarTitle({
  60. title: this.newTitle,
  61. success: () => {
  62. console.log('setNavigationBarTitle success')
  63. this.setLifeCycleNum(state.lifeCycleNum + 1)
  64. },
  65. fail: () => {
  66. console.log('setNavigationBarTitle fail')
  67. this.setLifeCycleNum(state.lifeCycleNum - 1)
  68. },
  69. complete: () => {
  70. console.log('setNavigationBarTitle complete')
  71. this.setLifeCycleNum(state.lifeCycleNum + 1)
  72. }
  73. })
  74. },
  75. setNavigationBarLongTitle() {
  76. uni.setNavigationBarTitle({
  77. title: this.longTitle,
  78. success() {
  79. console.log('setNavigationBarTitle success')
  80. },
  81. fail() {
  82. console.log('setNavigationBarTitle fail')
  83. },
  84. complete() {
  85. console.log('setNavigationBarTitle complete')
  86. }
  87. })
  88. },
  89. // 自动化测试
  90. getLifeCycleNum() : number {
  91. return state.lifeCycleNum
  92. },
  93. // 自动化测试
  94. setLifeCycleNum(num : number) {
  95. setLifeCycleNum(num)
  96. }
  97. },
  98. }
  99. </script>