当前位置:网站首页>WeChat applet page syntax
WeChat applet page syntax
2022-08-01 00:20:00 【A bunny who loves carrots】
Applet page syntax
一.使用数据
Used by the applet page动态数据are on the corresponding pagejs文件的data内.
// pages/index/index.js
Page({
/** * 1.页面的初始数据 */
data: {
msg: 'Data initialization test'
},
/** * 生命周期函数--监听页面加载 * 加载indexThis function is triggered when the page is displayed,加载 完成后调用onShow()The function renders the page */
onLoad(options) {
console.log('页面加载函数 onLoad()')
// 2.this当前页面的实例对象
console.log(this)
// 3.Use page data
console.log(this.data.msg)
// Edit in 2 seconds
setTimeout(() => {
// 4.修改页面数据
this.setData({
msg: '修改后的msg数据'
})
console.log(this.data.msg)
},2000)
},
/** * 生命周期函数--监听页面初次渲染完成 */
onReady() {
},
/** * 生命周期函数--监听页面显示 */
onShow() {
console.log("onShow()")
},
})
- 单向数据流;model → view
- Modifying data is synchronous;
二. Data hijacking and proxies
1.Object.definePropertyImplement data hijacking and proxying
let person = {
username: '陈三', age: 18
}
let _this = {
}
// 用_this代理person(通过数据劫持set,修改数据时,setterHijack the data to be modified,setter来进行修改;数据代理get)
for (let item in person) {
// console.log(item)
Object.defineProperty(_this, item, {
get() {
return person[item]
},
set(value) {
person[item] = value
}
})
}
console.log(_this)
console.log(_this.username, _this.age)
/* 总结: _this的get()方法获取person的值;数据代理. _this的set()方法修改person的值;数据劫持. */
_this.username = '李四'
_this.age = 81
console.log(_this.username, _this.age)
2.vueThe principle of data proxy and hijacking
三.小程序事件
事件的回调函数
with the function period sumdataObject siblings are written directly inPage({})
内
1.事件分类
事件 事件分类
冒泡事件 bind+事件 (The event of the target element is fired first,The parent element event is then fired from the inside out)
非冒泡事件 catch+事件 (Only fire the event of the target element)
四.路由跳转
API → 路由
1.wx.navigateTo
保留当前页面,跳转到应用内的某个页面.最多十层.
url要求: 从/目录开始写
/
+ pages/页面
/** * Jump routing function,跳转到logs页面 */
//toLogs(){等价于
toLogs:function(){
wx.navigateTo({
url: '/pages/logs/logs',
})
},
2.Configure the specified page window
在对应页面的json
内配置
操作:
Write the corresponding content directly, 不用window
{
"navigationBarTitleText": "启动日志", //对应内容
"usingComponents": {
}
}
五.生命周期
The page is displayed for the first time: onLoad → onShow → onReady
// pages/index/index.js
Page({
/** * 1.页面的初始数据 */
data: {
userName: '孤',
msg: 'Data initialization test'
},
/** * Jump routing function,跳转到logs页面 */
toLogs: function () {
wx.navigateTo({
url: '/pages/logs/logs',
})
// wx.reLaunch({
// url: '/pages/logs/logs',
// })
},
/** * 生命周期函数--监听页面加载 * 加载indexThis function is triggered when the page is displayed,加载 完成后调用onShow()The function renders the page */
onLoad(options) {
console.log('页面加载函数 onLoad()')
// debugger;
// 2.this当前页面的实例对象
// console.log(this)
// 3.Use page data
// console.log(this.data.msg)
// Edit in 2 seconds
// setTimeout(() => {
// 4.修改页面数据
// this.setData({
// msg: '修改后的msg数据'
// })
// console.log(this.data.msg)
// },2000)
},
/** * 生命周期函数--监听页面初次渲染完成 */
onReady() {
console.log('初次渲染完成 onReady()')
},
/** * 生命周期函数--监听页面显示 */
onShow() {
console.log("页面显示(多次执行) onShow()")
},
/** * 生命周期函数--监听页面隐藏 */
onHide() {
console.log("页面隐藏 onHide()")
},
/** * 生命周期函数--监听页面卸载 */
onUnload() {
console.log("页面卸载 onUnload()")
},
/** * 页面相关事件处理函数--监听用户下拉动作 */
onPullDownRefresh() {
console.log("用户下拉 onPullDownRefresh()")
},
/** * 页面上拉触底事件的处理函数 */
onReachBottom() {
console.log("上拉触底事件的处理函数 onReachBottom()")
},
/** * 用户点击右上角分享 */
onShareAppMessage() {
console.log("点击右上角分享 onShareAppMessage()")
}
})
边栏推荐
- 2022年最新重庆建筑八大员(电气施工员)模拟题库及答案
- SQL injection Less46 (injection after order by + rand() Boolean blind injection)
- Inheritance and friend, static member relationship
- Google "Cloud Developer Quick Checklist"; Tsinghua 3D Human Body Dataset; SenseTime "Universal Vision Framework" open class; Web3 Minimalist Getting Started Guide; Free Books for Efficient Deep Learni
- qlib量化源码分析:qlib/qlib/contrib/model/gbdt.py
- Interview Blitz 69: Is TCP Reliable?Why?
- Named Entity Recognition - Model: BERT-MRC
- Handwritten a simple web server (B/S architecture)
- 什么时候可以使用 PushGateway
- Web3.0: Building an NFT Market (1)
猜你喜欢
新产品如何进行网络推广?
Advanced Algebra _ Proof _ Any matrix is similar to an upper triangular matrix
[MATLAB project combat] LDPC-BP channel coding
C# Rectangle basic usage and picture cutting
【MATLAB项目实战】LDPC-BP信道编码
Kyoto University: Masaki Waga | Dynamic Masking for Reinforcement Learning in Black Box Environments
[Microservice] Distributed Transaction Solution - Seata
Likou Binary Tree
Recommendation system: Summary of common evaluation indicators [accuracy rate, precision rate, recall rate, hit rate, (normalized depreciation cumulative gain) NDCG, mean reciprocal ranking (MRR), ROC
Matlab/Arcgis processing nc data
随机推荐
Notes on how to use zeno
消息队列存储消息数据的MySQL表格
Difference Between Stateless and Stateful
Thinking and Implementation of Object Cache Service
浏览器下载快捷方式到桌面(PWA)
Matlab / Arcgis处理nc数据
Web3.0:构建 NFT 市场(一)
Team of Professor Chen Jianyu of Tsinghua University | Contact Safety Reinforcement Learning Framework Based on Contact-rich Robot Operation
开源好用的 流程图绘制工具 drawio
力扣2326、197
内核对设备树的处理
一体化步进电机在无人机自动机场的应用
编程语言是什么
C# Rectangle基本用法和图片切割
【读书笔记->数据分析】02 数据分析准备
【FPGA教程案例43】图像案例3——通过verilog实现图像sobel边缘提取,通过MATLAB进行辅助验证
pycaret源码分析:下载数据集\Lib\site-packages\pycaret\datasets.py
[Microservice] Distributed Transaction Solution - Seata
Nmap Operation Manual - Full Version
Southern University of Science and Technology: Xiaoying Tang | AADG: Automatic Enhancement for Generalization in the Field of Retinal Image Segmentation