Three important files: app.js, app.json, app.wxss
app.js 可以监听并处理小程序的生命周期函数、声明全局变量 app.json 小程序全局配置,在该文件中配置小程序由哪些页面组成、配置小程序窗口背景色、导航条样式、默认标题等
Note: Do not add any comments
Each page path + page name in the WeChat applet must be written in the pages attribute of app.json, and the first one in pages The page is the homepage of the mini program
Each mini program page consists of four different suffix files with the same name under the same path, such as: index.js, index.wxml, index.wxss, index.json
The file with .js suffix is a script file, the .json suffix is a configuration file, the .wxss suffix is a style sheet file, and the .wxml suffix is a page structure The file
index.js file can monitor and process page life cycle functions, obtain applet instances, declare and process data, respond to page interactive events, etc.
To facilitate developers to reduce configuration items, the four files describing the page must have the same path and file name
getApp() 获取当前App实例 getCurrentPages() 获取当前页面栈
Note Matters: The framework does not run in the browser, such as document, window, etc. cannot be used
onLaunch 生命周期函数--监听小程序初始化(全局只触发一次) onShow 生命周期函数--监听小程序显示 当小程序启动或从后台进入前台显示触发 onHide 生命周期函数--监听小程序隐藏 当小程序从前台进入后台会触发 onError 错误监听函数
When a script error occurs in the applet or the api call fails, it will be triggered with an error message
Development Users can add any function or data to the Object parameter value, and use this to access
data 页面的初始数据 onLoad 生命周期函数--监听页面加载 onReady 生命周期函数--监听页面初次渲染完成 onShow 生命周期函数--监听页面显示 onHide 生命周期函数--监听页面隐藏 onUnload 生命周期函数--监听页面卸载 onPullDownRefresh 页面相关事件处理函数--监听用户下拉动作 onReachBottom 页面上拉触底事件处理函数 onShareAppMessage 用户点击右上角转发 onPageScroll 页面滚动触发事件处理函数
The above is the detailed content of Introduction to WeChat Mini Programs. For more information, please follow other related articles on the PHP Chinese website!