Understanding of uniapp configuration file

Posted by steve55 on Mon, 07 Mar 2022 08:53:14 +0100

First of all, uniapp is similar to vue. There are pages when building projects JSON this file
First introduce the next basic pages JSON file

{
  "pages": [{
    "path": "pages/component/index",
    "style": {
      "navigationBarTitleText": "assembly"
    }
  }, {
    "path": "pages/API/index",
    "style": {
      "navigationBarTitleText": "Interface"
    }
  }, {
    "path": "pages/component/view/index",
    "style": {
      "navigationBarTitleText": "view"
    }
  }],
  "globalStyle": {
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "demonstration",
    "navigationBarBackgroundColor": "#F8F8F8",
    "backgroundColor": "#F8F8F8"
  },
  "tabBar": {
    "color": "#7A7E83",
    "selectedColor": "#3cc51f",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [{
      "pagePath": "pages/component/index",
      "iconPath": "static/image/icon_component.png",
      "selectedIconPath": "static/image/icon_component_HL.png",
      "text": "assembly"
    }, {
      "pagePath": "pages/API/index",
      "iconPath": "static/image/icon_API.png",
      "selectedIconPath": "static/image/icon_API_HL.png",
      "text": "Interface"
    }]
  }
}

There are four categories of configuration items

Configuration itemtypeIs it emptyeffect
globalStyleObjectnoSet the window performance of the default page
pagesObject ArrayyesSet page path and window performance
tabBarObjectnoSet the performance of the bottom tab
conditionObjectnoBoot mode configuration

Then we first introduce
globalStyle
It is used to set the application's status bar, navigation bar, title, window background color, etc.
The configuration is as follows

Configuration itemtypeeffect
navigationBarBackgroundColorHexColor (#000000)Navigation bar background color
navigationBarTextStyleString (white )Navigation bar title color, only black/white is supported
navigationBarTitleTextStringNavigation bar title text content
navigationStyleString(default )Navigation bar style. Only default/custom is supported
backgroundColorHexColor (#ffffff )Background color of window wechat applet

Note: navigationStyle is only available in pages The settings in JSON - > globalstyle take effect. After opening custom, all windows have no navigation bar.

Then
pages
It receives an array to specify which pages the application consists of. Each item represents the information of the corresponding page. When adding / reducing pages in the application, the pages array needs to be modified.
The file name does not need to write a suffix, and the framework will automatically find the page resources under the path.
There are usually two objects in it, one is page and the other is style
You need to find the file path in pege

Then there are configuration items

Configuration itemtypeeffect
navigationBarBackgroundColorHexColor (#000000)Navigation bar background color
navigationBarTextStyleString (white )Navigation bar title color, only black/white is supported
navigationBarTitleTextStringNavigation bar title text content
backgroundColorHexColor (#ffffff )Background color of window wechat applet
backgroundTextStyleString(dark )The style of drop-down loading only supports dark/light
enablePullDownRefreshBoolean(false )Whether to enable the pull-down refresh, see the relevant event handling functions on the page for details
onReachBottomDistanceNumber (50)The distance from the bottom of the page when the pull-up bottom event is triggered, in px
navigationStyleString (default )Navigation bar style. Only default/custom is supported. Custom mode can customize the navigation bar, leaving only the capsule button in the upper right corner. Wechat applet
backgroundColorTopString (#ffffff)The background color of the top window. Wechat applet and iOS
backgroundColorBottomString (#ffffff)The background color of the bottom window. Wechat applet and iOS

Note: the first item of the pages node is the application entry page (i.e. the home page).

{
  "pages": [{
      "index": {
        "path": "pages/index/index",
        "style": {
            "navigationBarTitleText": "home page",//Set page title text
          "enablePullDownRefresh":true//Enable pull-down refresh
        }
      }
    },
    ...
  ]
}

File instance

tabBar
If the application is a multi tab application, you can specify the performance of the tab bar and the corresponding page displayed during tab switching through the tabBar configuration item.
When position is set to top, icon will not be displayed
The list in the tabBar is an array, which can only be configured with at least 2 and at most 5 tabs. The tabs are sorted in the order of the array.
First of all, his attributes are as follows

Configuration itemtypeIs it emptyeffect
colorHexColoryesDefault color of text on tab
selectedColorHexColoryesThe color when the text on the tab is selected
backgroundColorHexColoryesBackground color of tab
borderStyleString(black)noColor on bbar / white border only
listArrayyesFor the list of tabs, see the description of the list attribute. There are at least 2 and at most 5 tabs
positionString(bottom )yesOptional values are bottom and top

Where list is an array, and each item of the array is an object. Its configuration is as follows

Configuration itemtypeIs it emptyeffect
pagePathStringyesThe page path must be defined in pages first
textStringyesButton text on tab
iconPathStringnoImage path. The icon size is limited to 40kb. The recommended size is 81px * 81px. When the position is top, this parameter is invalid and network images are not supported
selectedIconPathStringnoWhen selected, the icon size is limited to 40kb, and the recommended size is 81px * 81px. When the position is top, this parameter is invalid

Code example

"tabBar": {
    "color": "#7A7E83",
    "selectedColor": "#3cc51f",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [{
      "pagePath": "pages/component/index",
      "iconPath": "static/image/icon_component.png",
      "selectedIconPath": "static/image/icon_component_HL.png",
      "text": "assembly"
    }, {
      "pagePath": "pages/API/index",
      "iconPath": "static/image/icon_API.png",
      "selectedIconPath": "static/image/icon_API_HL.png",
      "text": "Interface"
    }]
  }

condition
Startup mode configuration, which only takes effect during development, is used to simulate the scene of direct access to the page, such as: after the applet is forwarded, the user clicks the open page.

The properties are as follows

Configuration itemtypeIs it emptyeffect
currentNumberyesThe currently active mode, the index value of the list node
listArrayyesStartup mode list

The list attribute is as follows

Configuration itemtypeIs it emptyeffect
nameStringyesStartup mode name
pathStringyesStart page path
queryStringnoThe startup parameters can be obtained in the onLoad function of the page

The code configuration is as follows

"condition": { //Mode configuration, effective only during development
    "current": 0, //Currently active mode (index entry of list)
    "list": [{
            "name": "swiper", //Mode name
            "path": "pages/component/swiper/swiper", //Startup page, required
            "query": "interval=4000&autoplay=false" //The startup parameters are obtained in the onLoad function of the page.
        },
        {
            "name": "test",
            "path": "pages/component/switch/switch"
        }
    ]
}

Topics: Javascript Vue.js uniapp