set-navigation-bar-title.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <view class="page">
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap">
  5. <view class="uni-helllo-text">
  6. 本页标题栏是uni-app的默认配置,开发者可在pages.json里配置文字内容及标题颜色,也可通过api接口将其改变。
  7. </view>
  8. <view class="uni-btn-v">
  9. <button type="default" @click="setText">改变标题栏文字</button>
  10. <button type="primary" @click="setBg">改变标题栏颜色</button>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. title: 'nav-default',
  20. hasSetText:false,
  21. hasSetBg:false
  22. }
  23. },
  24. methods: {
  25. setText() {
  26. this.hasSetText = !this.hasSetText;
  27. uni.setNavigationBarTitle({
  28. title: this.hasSetText ? "Hello uni-app" : "默认导航栏"
  29. })
  30. },
  31. setBg() {
  32. this.hasSetBg = !this.hasSetBg;
  33. uni.setNavigationBarColor({
  34. frontColor: this.hasSetBg ? "#000000" : "#ffffff",
  35. backgroundColor: this.hasSetBg ? "#F8F8F8" : "#007AFF"
  36. })
  37. }
  38. }
  39. }
  40. </script>
  41. <style>
  42. </style>