Home > Web Front-end > uni-app > How to hide the header in uniapp

How to hide the header in uniapp

PHPz
Release: 2023-04-23 09:53:45
Original
4027 people have browsed it

With the development of mobile applications, many developers have begun to use a cross-platform development framework called uniapp to develop applications. Some apps need to hide the header in different pages, so in this article, we will explain how to make this work in uniapp.

Uniapp is a cross-platform development framework that can provide a consistent user experience for applications on different platforms. The framework is built based on Vue.js and supports multiple platforms, including WeChat mini-programs, Alipay mini-programs, H5, etc. Using uniapp allows us to avoid writing code separately for each platform, thereby improving development efficiency and code quality.

If you want to hide the page header in uniapp, you need to do the following:

  1. Define the navigation bar state of the page in your pages.json file

pages.json is the file used to manage page configuration in uniapp. From there you can define different properties for the page, including the navigation bar state. A navigation bar can display a title, back button, menu button, and more at the top of the page. If you want to hide the title bar, add the "navigationBarHidden" attribute in the page configuration file and set it to "true".

For example, in my pages.json file, if I want to hide the title bar, I need to set it like this:

{
  "pages": [
    {
      "path": "pages/home/home",
      "style": {
        "navigationBarTitleText": "首页",
        "navigationBarBackgroundColor": "#ffffff",
        "navigationBarTextStyle": "black",
        "navigationBarHidden":true
      }
    }
  ]
}
Copy after login
  1. Add the corresponding style to the page

Although we set the hidden status of the title bar in the page configuration file, this is just a configuration and CSS styles need to be added accordingly to the page to ensure the effect. In your page CSS style file, you can add the following styles to your page to hide the title bar:

.page {
  position: relative;
  padding-top: 0 !important;
}

header {
  display: none !important;
}
Copy after login

These styles will set a specific position, top margin, and hidden header for the page. Make sure to add these styles to the page with the header hidden attribute.

  1. Add corresponding logic to your page

In your page logic, you need to access the navigation bar state and ensure the effect is achieved. You can access the navigation bar state through the following code:

onLoad: function () {
  wx.setNavigationBarTitle({
    title: '页面标题'
  })
  wx.hideNavigationBarLoading()
  wx.showNavigationBarLoading()
}
Copy after login

In this example, we can access the navigation bar in the page load function, by setting the title, hiding and showing the loading state to achieve the effect.

In this article, we show you how to hide the title bar in uniapp. This is essential if you need to change the navigation bar state of a page while developing an application. We hope you found this guide helpful, and if you have any questions, please share them with us in the comments.

The above is the detailed content of How to hide the header in uniapp. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template