Home  >  Article  >  Web Front-end  >  How to set up landing page in uniapp

How to set up landing page in uniapp

PHPz
PHPzOriginal
2023-04-20 15:02:43816browse

With the in-depth development of the mobile Internet, more and more companies choose to build their own APPs to improve user experience and brand image. In order to reduce development costs and improve development efficiency, many companies choose to use cross-platform development frameworks to build APPs, and Uniapp is an excellent open source framework among them.

When building a Uniapp application, we need to define the entry page, which is the page that is loaded first after the application is started. It is usually called the landing page or home page. In this article, we will detail how to create and set up a landing page for your Uniapp application.

Step one: Create Uniapp project

Download the latest version of Uniapp from the Uniapp official website and install it in the local environment:

$ npm install --global @vue/cli@3.0.0-beta.10
$ vue create -p dcloudio/uni-preset-vue my-project

Enter the above command on the command line, that is A uni-app project can be created.

Step 2: Create a landing page

In the src directory, we can create our own homepage vue page. You can choose your favorite editor to write. Here we use the HbuilderX editor to create an index.vue file. The code is as follows:

<template>
  <view class="container">
    <text class="text">这是我的Uniapp应用程序的落地页</text>
  </view>
</template>

<style>
  .container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .text {
    font-size: 24px;
  }
</style>

Simply put, we created a container tag and a text tag. The container Used to center text content and make it appear centered. For demonstration purposes here, the text content we set is just "This is the landing page of my Uniapp application".

Step 3: Set up the landing page

After we create the landing page, we need to tell the Uniapp application that this is our entry page and need to be configured in the pages.json file. Open the pages.json file and add the following code:

{
  "pages": [
    {
      "path": "pages/index/index",
      "style": {
        "navigationBarTitleText": "Uniapp落地页"
      }
    }
  ],
  "globalStyle": {
    "navigationBarTextStyle": "white",
    "navigationBarBackgroundColor": "#000"
  }
}

In this pages.json file, we define all the pages of the application, there is only the "index" page we just created. The "navigationBarTitleText" attribute is used to set the navigation bar title text. In addition, we should also set the global navigation bar style.

Step 4: Set the application startup page

We have set the landing page, but we also need to tell Uniapp what the application startup page is. Add the following content to the pages.json file:

{
  "pages": [
    {
      "path": "pages/index/index",
      "style": {
        "navigationBarTitleText": "Uniapp落地页"
      }
    }
  ],
  "globalStyle": {
    "navigationBarTextStyle": "white",
    "navigationBarBackgroundColor": "#000"
  },
  "tabBar": {
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "首页",
        "iconPath": "static/tabbar/home.png",
        "selectedIconPath": "static/tabbar/home-active.png"
      }
    ]
  },
  "launchPage": {
    "path": "pages/index/index"
  }
}

Here we use the tabBar and launchPage attributes. tabBar is used to define the bottom navigation bar of the application, and launchPage is used to set the application launch page. We set the startup page to the "index" page we just created.

Here we also need to define several properties for the bottom navigation bar of the application. Only one "homepage" is defined here. Other pages can be defined according to needs, and the iconPath and selectedIconPath properties are used to define navigation. The icon corresponding to the bar and the icon of the active state.

Step 5: Start the application

Now that we have set up the landing page and startup page, we can start the application to see the effect. Enter the following command in the command console to start the application:

$ npm run dev:%PLATFORM%

The %PLATFORM% here represents the platform you are using later, which can be h5, app-plus, mp-weixin and other platforms.

Now, we have successfully created and set up the landing page of the Uniapp application. Whether you are building a web application or a cross-platform mobile application, Uniapp is a powerful development framework that allows you to create impressive applications.

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

Statement:
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