当前位置:网站首页>微信小程序学习笔记2
微信小程序学习笔记2
2022-07-26 09:22:00 【~轻舟~】
一、小程序的启动
在app.json的pages中可以看到小程序的所有页面路径,写在pages字段第一个页面就是这个小程序的首页
微信客户端将首页代码装载然后通过小程序底层的一些机制,就可以渲染这个页面
然后我们看看小程序启动后执行的函数吧!
程序被执行会执行生命周期函数,这跟其它客户端程序一样。
小程序的生命周期函数是在app.js中onLaunch中
App({
onLaunch: function () {
// 小程序启动之后 触发
}
//小程序显示的时候触发
onShow:function(){
console.log("生命周期函数-坚挺小程序显示的时候触发");
},
//小程序隐藏的时候触发
onHide:function(){
console.log("生命周期函数-坚挺小程序隐藏的时候触发");
},
//全局的属性
globalData: {
userInfo: null
}
})二、程序与页面
我们可以看到一般一个文件夹下会有四种文件,客户端会先根据.json配置生成一个界面,顶部颜色和文字可以在json文件定义好。紧接着会装载页面的wxml结构和wxss样式。最后装在.js,js大体是这样的
//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.
},
onPageScroll: function() {
// Do something when page scroll
},
// Event handler.
viewTap: function() {
this.setData({
text: 'Set some data for updating view.'
}, function() {
// this is setData callback
})
},
customData: {
hi: 'MINA'
}
})Page是页面构造器,这个构造器就生成了一个页面。生成页面的时候会把data数据和wxml一起渲染出最终的结构,渲染结束后页面会受到onLoad回调,我们可以在回调中处理自己的逻辑。
三、组件
组件对应程序开发的各种控件,不过小程序控件进行了一定的整合。
组件列表:(七大类)
视图容器有view、scroll-view 、swiper(视图容器、可滚动视图容器、滑块视图容器)
基本内容:
icon(图标)text(文字)progress(进度条)
表单:
button(按钮)form(表单)input(输入框)。。。
……
好,接下来,开始小程序之旅!!!
边栏推荐
- 2022 chemical automation control instrument operation certificate test question simulation test platform operation
- Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
- Selection and practice of distributed tracking system
- Mysql事务
- tornado之多进程服务
- Unity topdown character movement control
- Elastic APM安装和使用
- Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
- NTT (fast number theory transformation) polynomial inverse 1500 word analysis
- arcgis的基本使用1
猜你喜欢

服务器内存故障预测居然可以这样做!

Qtcreator reports an error: you need to set an executable in the custom run configuration

Windows backs up the database locally by command

Redis principle and use - Basic Features

JVM command induction

Innovus is stuck, prompting x error:

Server memory failure prediction can actually do this!

Vertical search

【线上死锁分析】由index_merge引发的死锁事件

Bloom filter
随机推荐
JS - DataTables control on the number of displays per page
Windows通过命令备份数据库到本地
[shutter -- layout] detailed explanation of the use of align, center and padding
Zipkin installation and use
HBuilderX 运行微信开发者工具 “Fail to open IDE“报错解决
jvm命令归纳
李沐d2l(五)---多层感知机
分布式跟踪系统选型与实践
PHP 之 Apple生成和验证令牌
服务器内存故障预测居然可以这样做!
Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
2B和2C
多层嵌套后的 Fragment 懒加载实现
2B and 2C
Unity topdown character movement control
多项式开根
Cat安装和使用
(2006,Mysql Server has gone away)问题处理
Simple message mechanism of unity
大二上第五周学习笔记