当前位置:   article > 正文

uniapp自定义顶部导航栏

uniapp自定义顶部导航栏

 首先uniapp获取设备信息:uni.getSystemInfo或uni.getSystemInfoSync,可用于设置顶部安全区

留一个设备安全区的位置哦

然后在pages.json文件里配置自定义导航栏

  1. {
  2. "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
  3. {
  4. "path": "pages/index/index",
  5. "style": {
  6. "navigationBarTitleText": "济源市仁新医院",
  7. "navigationStyle": "custom" //页面使用自定义导航栏属性,微信小程序不给直接修改导航栏字体的大小
  8. }
  9. }
  10. ],
  11. "globalStyle": {
  12. "navigationBarTextStyle": "#fff",
  13. "navigationBarTitleText": "uni-app",
  14. "navigationBarBackgroundColor": "#00DACA",
  15. "backgroundColor": "#F8F8F8"
  16. },
  17. "uniIdRouter": {}
  18. }
  1. <template>
  2. <view class="">
  3. <view class="custom-navbar"
  4. :style="{height:height, backgroundColor: backgroundColor,width:'100%',paddingTop: sysTop + 'px'}">
  5. <text class="navbar-title" :style="{color: titleColor, fontSize: fontSize + 'px'}">{{ title }}</text>
  6. </view>
  7. </view>
  8. </template>
  9. <script setup>
  10. export default {
  11. data() {
  12. return {
  13. title: '济源市仁新医院',
  14. titleColor: '#fff',
  15. backgroundColor: '#00DACA',
  16. fontSize: 18,
  17. height: '100px',
  18. sysTop: '0'
  19. }
  20. },
  21. onLoad() {
  22. var that = this;
  23. let sysInfo = uni.getSystemInfoSync().statusBarHeight;
  24. console.log(sysInfo);
  25. that.sysTop = sysInfo
  26. },
  27. methods: {
  28. }
  29. }
  30. </script>
  31. <style scoped>
  32. .custom-navbar {
  33. box-sizing: border-box;
  34. display: flex;
  35. align-items: center;
  36. justify-content: center;
  37. position: fixed;
  38. top: 0;
  39. left: 0;
  40. right: 0;
  41. z-index: 999;
  42. }
  43. .navbar-title {
  44. font-weight: 600;
  45. }
  46. </style>

效果图

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/474048
推荐阅读
相关标签
  

闽ICP备14008679号