当前位置:网站首页>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()")
}
})
边栏推荐
- SVN服务器搭建+SVN客户端+TeamCity集成环境搭建+VS2019开发
- 如何设计高可用高性能中间件 - 作业
- Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
- Nmap Operation Manual - Full Version
- 硬件设备计算存储及数据交互杂谈
- 开源好用的 流程图绘制工具 drawio
- Flink 1.13(八)CDC
- C# Rectangle basic usage and picture cutting
- Flutter教程之 02 Flutter 桌面程序开发入门教程运行hello world (教程含源码)
- 谷歌『云开发者速查表』;清华3D人体数据集;商汤『通用视觉框架』公开课;Web3极简入门指南;高效深度学习免费书;前沿论文 | ShowMeAI资讯日报
猜你喜欢
随机推荐
博弈论(Depu)与孙子兵法(42/100)
Qlib quantitative source analysis: qlib/qlib/contrib/model/GBDT py
如何撰写出一篇优质的数码类好物推荐文
IPD process terminology
基于simulink的Active anti-islanding-AFD主动反孤岛模型仿真
微信小程序之小程序页面语法
Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
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
Binary tree traversal non-recursive program -- using stack to simulate system stack
助力数字政府建设,中科三方构建域名安全保障体系
精心总结十三条建议,帮你创建更合适的MySQL索引
Web3.0:构建 NFT 市场(一)
Basic use of vim - bottom line mode
IPD流程专业术语
MLP神经网络,GRNN神经网络,SVM神经网络以及深度学习神经网络对比识别人体健康非健康数据
面试题:实现死锁
SQL injection Less47 (error injection) and Less49 (time blind injection)
How to Design High Availability and High Performance Middleware - Homework
WindowInsetsControllerCompat is simple to use
Pylint检查规则中文版