当前位置:网站首页>App. In wechat applet JS files, components, APIs
App. In wechat applet JS files, components, APIs
2022-04-23 10:25:00 【Bitter sea 123】
app.js file :
Every applet needs to be in app.js Call in App Method to register an applet instance .
App({
//App Instantiation , There is only one... In the whole applet App example , Share all pages
onLaunch: function () {
//onLaunch Trigger after the applet starts
},
onShow: function () {
//onShow Applet startup , Or trigger when entering the foreground display from the background
},
onHide: function () {
//onHide Trigger when the applet enters the background from the foreground
},
onError: function () {
//onError Script error in applet or API Trigger when calling to report an error
},
onPageNotFound: function () {
//onPageNotFound Triggered when the page to be opened by the applet does not exist
},
onUnhandledRejection: function () {
//onUnhandledRejection The applet has unhandled Promise Trigger when rejected
},
onThemeChange: function () {
//onThemeChange Triggered when the system switches topics
},
// You can customize any type of function or variable of Tianjian , use this Accessible , Such as :
names:'jack'
})
On the page js file :
For each page in the applet , All need to be mapped on the page js Use... In the document page Go to the registration page , Specify the initial data for the page 、 Lifecycle Callback 、 Event handling functions, etc .
Page({
//page For the page builder , Generate a page
data: {
//data Define initialization data , Hui He wxml Use {
{text}} Rendering
text: "hello"
},
options: {
//options Define the component options of the page
},
onLoad: function() {
// Execute... When the page is created
},
onShow: function() {
// Execute... When the page appears in the foreground
},
onReady: function() {
// When the page is rendered for the first time
},
onHide: function() {
// Execute when the page changes from foreground to background
},
onUnload: function() {
// Execute... When the page is destroyed
},
onPullDownRefresh: function() {
// Execute when the pull-down refresh is triggered
},
onReachBottom: function() {
// Execute when the page hits the bottom ( Pull up )
},
onShareAppMessage: function () {
// When a page is shared by a user
},
onShareTimeline: function () {
// When the page is shared by the user to the circle of friends
},
onAddToFavorites: function () {
// Execute when the page is favorite by the user
},
onPageScroll: function() {
// Execute... When the page scrolls
},
onResize: function() {
// Execute when page size changes
},
onTabItemTap(item) {
// tab Execute when clicked
console.log(item.index)
console.log(item.pagePath)
console.log(item.text)
},
// Event response function ( Custom function name , Such as :viewTap)
viewTap: function() {
this.setData({
//setData Reset value
text: 'word'
}, function() {
// Callback function executed after re assignment
})
},
// Free data
customData: {
hi: 'MINA',
lucky:'jack'
}
})
behaviors:
behaviors It can be used to make multiple pages have the same data fields and methods , Such as :
//behavior.js in :
module.exports = Behavior({
data: {
sharedText: ' Page common fields '
},
methods: {
sharedMethod: function() {
// Sharing method
}
}
})
// page.js in :
var myBehavior = require('./behavior.js')
Page({
behaviors: [myBehavior],// Use behaviors receive data
onLoad: function() {
console.log(this.data.sharedText)// adopt this Get the data
}
})
Component:
Component Constructors can be used to define components , call Component Constructor can specify the properties of the component 、 data 、 Such method , Document recommendation :https://developers.weixin.qq.com/miniprogram/dev/reference/api/Component.html, Such as :
Component({
behaviors: [],
// Attribute definitions ( See below for details )
properties: {
myProperty: {
// Property name
type: String,
value: ''
},
myProperty2: String // A simplified way to define
},
data: {
}, // Private data , Can be used for template rendering
lifetimes: {
// Life cycle function , It can be a function , Or one in methods The method name defined in the
attached: function () {
},
moved: function () {
},
detached: function () {
},
},
// Life cycle function , It can be a function , Or one in methods The method name defined in the
attached: function () {
}, // here attached Your statement will be lifetimes Field
ready: function() {
},
pageLifetimes: {
// The lifecycle function of the page where the component is located
show: function () {
},
hide: function () {
},
resize: function () {
},
},
methods: {
onMyButtonTap: function(){
this.setData({
// The way to update properties and data is similar to the way to update page data
})
},
// The internal approach suggests starting with an underline
_myPrivateMethod: function(){
// There will be data.A[0].B Set to 'myPrivateData'
this.setData({
'A[0].B': 'myPrivateData'
})
},
_propertyChange: function(newVal, oldVal) {
}
}
})
Components :
Applets provide a wealth of components for developers , Developers can combine various components to synthesize their own small programs . It's like HTML Of div, p Just like the label , Such as :
<map longitude=" Shenzhen longitude " latitude=" Shenzhen latitude " bindmarkertap=" Function triggered when clicking on the map " style='width:200px;height:200px' class='mapbox'></map><!--map Map components , Render a map to the page , Attributes can be added , As in the assembly -->
More component documentation is recommended :https://developers.weixin.qq.com/miniprogram/dev/component/
api:
In order to enable developers to easily adjust the capabilities provided by wechat , For example, get user information 、 Wechat payment, etc , The applet provides a lot of API For developers to use , Such as access to geographic information :
wx.getLocation({
type: 'wgs84',
success: (res) => {
var latitude = res.latitude // latitude
var longitude = res.longitude // longitude
}
})
more API Recommended reading :https://developers.weixin.qq.com/miniprogram/dev/api/
Tips : This article, pictures and other materials come from the Internet , If there is infringement , Please send an email to :[email protected] Contact the author to delete .
The author : misery
版权声明
本文为[Bitter sea 123]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231019252379.html
边栏推荐
- 203. Remove linked list elements (linked list)
- 定义链表(链表)
- DBA常用SQL语句(3)- cache、undo、索引和等待事件
- Realize data value through streaming data integration (3) - real-time continuous data collection
- 101. Symmetric Tree
- LeetCode 1249. Minimum remove to make valid parents - FB high frequency question 1
- 任意文件读取漏洞 利用指南
- Can Jerry's AES 256bit [chapter]
- 19. Delete the penultimate node of the linked list (linked list)
- Redis design and Implementation
猜你喜欢
Sim Api User Guide(4)
景联文科技—专业数据标注公司和智能数据标注平台
得到知识服务app原型设计比较与实践
Exercise questions and simulation test of refrigeration and air conditioning equipment operation test in 2022
深度选择器
Question bank and answers of Shanghai safety officer C certificate examination in 2022
101. Symmetric Tree
部署jar包
Net start MySQL MySQL service is starting MySQL service failed to start. The service did not report any errors.
Configuration of LNMP
随机推荐
DBA common SQL statements (5) - latch related
得到知识服务app原型设计比较与实践
Sim Api User Guide(8)
59、螺旋矩阵(数组)
SQL tuning series - SQL performance methodology
Realize data value through streaming data integration (2)
59. Spiral matrix (array)
DBA常用SQL语句(3)- cache、undo、索引和等待事件
第一章 Oracle Database In-Memory 相关概念(IM-1.1)
Jerry's more accurate determination of abnormal address [chapter]
Ansible cloud computing automation
Linked list intersection (linked list)
19. Delete the penultimate node of the linked list (linked list)
解决VMware卸载后再安装出现的问题
101. Symmetric Tree
通过流式数据集成实现数据价值(4)-流数据管道
深度选择器
Juc并发编程09——Condition实现源码分析
Jerry sometimes finds that the memory has been tampered with, but there is no exception. How should he find it? [chapter]
DBA common SQL statements (1) - overview information