nav-default.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. <!-- #ifndef MP-TOUTIAO -->
  11. <button type="primary" @click="setBg">改变标题栏颜色</button>
  12. <!-- #endif -->
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. title: 'nav-default',
  22. hasSetText:false,
  23. hasSetBg:false
  24. }
  25. },
  26. methods: {
  27. setText() {
  28. this.hasSetText = !this.hasSetText;
  29. uni.setNavigationBarTitle({
  30. title: this.hasSetText ? "Hello uni-app" : "默认导航栏"
  31. })
  32. },
  33. setBg() {
  34. this.hasSetBg = !this.hasSetBg;
  35. uni.setNavigationBarColor({
  36. frontColor: this.hasSetBg ? "#ffffff" : "#000000",
  37. backgroundColor: this.hasSetBg ? "#007AFF" : "#F8F8F8"
  38. })
  39. }
  40. }
  41. }
  42. </script>
  43. <style>
  44. </style>