当前位置:网站首页>Basic knowledge of wechat applet cloud development literacy chapter (I) document structure
Basic knowledge of wechat applet cloud development literacy chapter (I) document structure
2022-06-24 06:34:00 【User 3004405】
File structure
Global file
app.js file
This is the script code file of the applet , You can listen on this file , And deal with some of the lifecycle of the applet ( For example, some global variables )
In this app.js In the file , Need to use App() function , To register the program .
demonstration :
//app.js
App({
onLaunch: function () {
// When applet initialization is complete , Will trigger onLaunch( Global trigger only once )
},
onShow: function () {
// When the applet starts , Or enter the foreground display from the background , Will trigger onShow
},
onHide: function () {
// When the applet enters the background from the foreground , Will trigger onHide
},
onError: function (msg) {
// When a script error occurs in an applet , perhaps api When the call fails , Will trigger onError With error message
},
other:function(){
// Global function , Can be used by others on the project js A file called
},
globalData:{
// Global object
},
})
app.json file
The global configuration file of the applet
pages
To specify which pages the applet consists of
Accept an array , Each item is a string . Each item represents the 【 route + file name 】 Information , The first item in the array represents the initial page of the applet . Add... To the applet / Reduce pages , All need to pages Array to modify .
The file name does not need to be suffixed , Because the framework will automatically find the path .json,.js,.wxml,.wxss To integrate the four files .
for example :
{
"pages":[
"pages/index/index",
"pages/logs/logs"
]
}
remarks :pages You just need to write wxml Path to file , Other documents do not need to be written
window
Status bar for setting up applets 、 Navigation bar 、 title 、 Window background color
Example :
{
"window":{
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": " Wechat interface function demonstration ",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
}
}
tabBar
If our app is more than one tab application ( There is... At the bottom or top of the client window tab Column can switch pages ), Then we can pass tabBar Configuration item assignment tab Column performance , as well as tab The corresponding page displayed when switching .
Tip: Jump through the page (wx.navigateTo) Or page redirection (wx.redirectTo) The page arrived , Even if it is defined in tabBar Pages in configuration , The bottom... Will not be displayed tab bar .
tabBar Is an array , It can only be configured with a minimum of 2 individual 、 most 5 individual tab,tab Sort by array .
Example :
{
"tabBar": {
"color":"#818181",
"selectedColor":"#0082D7
"borderStyle":"white",
"list": [{
"pagePath": "pages/index/index",
"text": " home page ",
"iconPath":"images/tabbar/[email protected]",
"selectedIconPath":"images/tabbar/[email protected]"
}, {
"pagePath": "pages/me/me",
"text": " Set up ",
"iconPath":"images/tabbar/[email protected]",
"selectedIconPath":"images/tabbar/[email protected]
}]
}
}
networkTimeout
You can set the timeout of various network requests .
Example
{
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
}
}
debug
It can be opened in developer tools debug Pattern , In the developer tool's console panel , Debug information to info Given in the form of , The message is Page Registration of , Page routing , Data update , Events trigger . Can help developers quickly locate some common problems .
Example :
{
"debug": false
}
app.wxss file
Define the global style
Basically with css almost , Not much here
Inside a page
xxx.js
Logical main function
Page({
})
Example :
//index.js
Page({
data: {
text: "This is page data."
},
onLoad: function(options) {
// Do some initialize when page load.
},
onReady: function() {
// Do something when page ready.
},
onShow: function() {
// Do something when page show.
},
onHide: function() {
// Do something when page hide.
},
onUnload: function() {
// Do something when page close.
},
onPullDownRefresh: function() {
// Do something when pull down.
},
onReachBottom: function() {
// Do something when page reach bottom.
},
onShareAppMessage: function () {
// return custom share data when user share.
},
// Event handler.
viewTap: function() {
this.setData(
text: 'Set some data for updating view.'
})
},
customData: {
hi: 'MINA'
}
})
Example :
Page({
onShareAppMessage: function () {
return {
title: ' Custom share title ',
desc: ' Custom sharing description ',
path: '/page/user?id=123'
}
}
})
xxx.wxml
Use the components provided by wechat to replace html Elements
Example :
xxx.wxss
Applet style , And css The style is basically similar , There is no repetition here
In the wxss Edited in the file css style , Can only be used on the current page
xxx.json
Every applet page can also use .json File to configure the window representation of this page . Page configuration ratio app.json Global configuration is much simpler , Just settings app.json Medium window Content of configuration item , Configuration items in the page will overwrite app.json Of window The same configuration item in .
Page .json Only... Can be set window Related configuration items , To determine the window performance of this page , So there's no need to write window This key
Example :
{
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": " Wechat interface function demonstration ",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light"
}
边栏推荐
- Urban Waterlogging Monitoring and early warning system
- DHCP server setup
- TRTC applet custom message
- Analysis of official template of wechat personnel recruitment management system (II)
- In Tencent, my trial period summary
- Get the short video! Batch download of Kwai video (with source code)
- Risk management - Asset Discovery series - public web asset discovery
- TensorFlow 2 quickstart for beginners
- Project deployment for learning 3D visualization from scratch
- WordPress pill applet build applet from zero to one [install and configure WordPress site]
猜你喜欢

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
Fault analysis | using --force to batch import data leads to partial data loss

ServiceStack. Source code analysis of redis (connection and connection pool)

解读AI机器人产业发展的顶层设计
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database
Oracle case: ohasd crash on AIX

Technology is a double-edged sword, which needs to be well kept

The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales

【二叉数学习】—— 树的介绍

基于三维GIS系统的智慧水库管理应用
随机推荐
Linux Apache setting compression and caching
Provide SFTP connection for Amazon S3
Operation and maintenance dry goods | how to improve the business stability and continuity through fault recovery?
Network Overview
Analysis of official template of micro build low code (I)
How is a Clickhouse query completed?
When the VPC main network card has multiple intranet IP addresses, the server cannot access the network internally, but the server can be accessed externally. How to solve this problem
Why the computer can't start
Analysis and treatment of easydss flash back caused by system time
Coding platform project construction guide
Overview of related concepts of social network analysis
"Adobe international certification" design white must understand the color theory, absolutely full of dry goods
The 2021 Tencent digital ecology conference landed in Wuhan, waiting for you to come to the special session of wechat with low code
Attack and defense enlightenment: chromium component risk analysis and convergence
Just now, we received a letter of thanks from Bohai University.
Water conservancy RTU telemetry terminal
Project deployment for learning 3D visualization from scratch
WordPress pill applet build applet from zero to one [pagoda panel installation configuration]
Correct way to update Fedora image Yum source to Tencent cloud Yum source
What is domain name resolution? How to resolve domain name resolution errors