set-navigation-bar-color.uvue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <page-head title="setNavigationBarColor"></page-head>
  3. <view class="uni-padding-wrap uni-common-mt">
  4. <button @tap="setNavigationBarColor1" class="uni-btn">
  5. 设置导航条背景绿色,标题白色
  6. </button>
  7. <button @tap="setNavigationBarColor2" class="uni-btn">
  8. 设置导航条背景红色,标题黑色
  9. </button>
  10. <button @tap="goNavbarLite" class="uni-btn">
  11. 跳转自定义导航栏页面
  12. </button>
  13. </view>
  14. </template>
  15. <script>
  16. import { state, setLifeCycleNum } from '@/store/index.uts'
  17. export default {
  18. methods: {
  19. setNavigationBarColor1() {
  20. uni.setNavigationBarColor({
  21. frontColor: '#ffffff',
  22. backgroundColor: '#00ff00',
  23. success: () => {
  24. console.log('setNavigationBarColor success')
  25. this.setLifeCycleNum(state.lifeCycleNum + 1)
  26. },
  27. fail: () => {
  28. console.log('setNavigationBarColor fail')
  29. this.setLifeCycleNum(state.lifeCycleNum - 1)
  30. },
  31. complete: () => {
  32. console.log('setNavigationBarColor complete')
  33. this.setLifeCycleNum(state.lifeCycleNum + 1)
  34. }
  35. })
  36. },
  37. setNavigationBarColor2() {
  38. uni.setNavigationBarColor({
  39. frontColor: '#000000',
  40. backgroundColor: '#ff0000',
  41. success: () => {
  42. console.log('setNavigationBarColor success')
  43. this.setLifeCycleNum(state.lifeCycleNum + 1)
  44. },
  45. fail: () => {
  46. console.log('setNavigationBarColor fail')
  47. this.setLifeCycleNum(state.lifeCycleNum - 1)
  48. },
  49. complete: () => {
  50. console.log('setNavigationBarColor complete')
  51. this.setLifeCycleNum(state.lifeCycleNum + 1)
  52. }
  53. })
  54. },
  55. // 自动化测试
  56. getLifeCycleNum() : number {
  57. return state.lifeCycleNum
  58. },
  59. // 自动化测试
  60. setLifeCycleNum(num : number) {
  61. setLifeCycleNum(num)
  62. },
  63. goNavbarLite() {
  64. uni.navigateTo({
  65. url: '/pages/template/navbar-lite/navbar-lite'
  66. })
  67. }
  68. },
  69. }
  70. </script>