# Building the Home Page
The application home page displays air quality information of different cities. The home page provides two screens \(for two information bars\), which can be added as required. Each screen displays the air quality information of one city, including the Air Quality Index \(AQI\), city name, pollution level, update time, and data source.
The home page of [AirQuality](device-camera-visual-overview.md) consists of three parts:
- Title bar: displays the page title and provides an exit button. The title bar is fixed at the top of the page.
- Information bar: displays air quality information. Multiple information bars can be added based on user requirements and support looping scroll.
- Indicator bar: shows the position of the current screen among all screens. The indicator bar is fixed at the bottom of the page.
The following steps describe how to build the home page with a flexible layout that has three rows vertically arranged.
1. Add a root **
** to the **.hml** file. Note that each **.hml** file can contain only one root component. The sample code is as follows:
```
```
**class="container"** indicates the style used by the component. The **container** is a style class defined in the **index.css** file.
```
.container {
flex-direction: column;
height: 480px;
width: 960px;
}
```
The height and width of the root component **
** are set in the style class. Note that the height and width must be explicitly specified \(except for some components, such as ****\). Otherwise, the component may fail to display. In the **container** style class, the **flex-direction** attribute is set to **column**, which means that child components of **
** are vertically arranged from top to bottom for implementing the flexible page layout.
2. Add the title bar. The title bar consists of an exit button and title text that are horizontally arranged. Add a **
** to hold the title bar and set the **flex-direction** attribute to **row** to arrange the child components from left to right. Add an **** and a **** component in sequence. The sample code is as follows:
```
Air quality
```
Set component attributes, including the height, width, margin, and color.
```
.header {
width: 960px;
height: 72px;
}
.back {
width: 36px;
height: 36px;
margin-left: 39px;
margin-top: 23px;
}
.title {
width: 296px;
height: 40px;
margin-top: 20px;
margin-left: 21px;
color: #e6e6e6;
}
```
In the **.hml** file, **onclick="exitApp"** sets the click event for the **
** component. When the click event is triggered, the **exitApp\(\)** function is executed. The example definition of **exitApp\(\)** in **index.js** is as follows:
```
exitApp() {
console.log('start exit');
app.terminate();
console.log('end exit');
}
```
The **app.terminate\(\)** function is used to exit the program. Before using this function, you must import the **app** module by adding the following code at the beginning of **index.js**:
```
import app from '@system.app'
```
After the code is compiled, run the project on the simulator. The following figure shows the display effect.
**Figure 1** Title bar
![](figures/title-bar.png "title-bar")
3. The **** component is required to implement the switching between screens.
Add a **** to the root node.
```
Air quality
```
- Use **class="**swiper**"** to set the height and width of the component. The sample code is as follows:
```
.swiper {
height: 385px;
width: 960px;
}
```
- **index="\{\{swiperPage\}\}" duration="500" onchange="swiperChange"** sets the component attribute and event. **duration="500"** indicates that the duration of the swiping animation is 500 ms.
- **index="\{\{swiperPage\}\}"** specifies the index of the child component of ****. **\{\{swiperPage\}\}** indicates that the index value is dynamically bound to the **swiperPage** variable in the JavaScript code. The index value changes with the **swiperPage** value.
- **onchange="swiperChange"** binds the change event of the **** component to the **swiperChange** function. The JavaScript code is as follows:
```
// Import the router module for page switching.
import router from'@system.router'
import app from '@system.app'
export default {
// Define parameters.
data: {
// By default, the first page is displayed.
swiperPage: 0
},
onInit () {
},
exitApp(){
console.log('start exit');
app.terminate();
console.log('end exit');
},
// Swiping event, which saves the index value of the current . The index value is saved to the swiperPage variable each time a swiping occurs.
swiperChange (e) {
this.swiperPage = e.index;
}
}
```
4. Set the information about a city to be displayed on a screen. On each screen, information of different types is displayed using different components.
Add two **** as child components \(directional layout\) to ****. Add ****, ****, **