1.app.js包含整个应用的生命周期函数,其中数据是全局的,可以在小程序所有js中调用,其他js中只需要通过getApp()获取app对象即可调用。以下是app.js的基本结构。官网详细介绍
App({onLaunch:function(options){//Dosomethinginitialwhenlaunch.},onShow:function(options){//Dosomethingwhenshow.},onHide:function(){//Dosomethingwhenhide.},onError:function(msg){console.log(msg)},globalData:'Iamglobaldata'})小程序全局样式app.wss2.app.wss中定义的样式可在所有页面中使用。方便码农们统一定义样式。
3.app.wss内容如下:
/**app.wxss**/.container{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:space-between;background-color:#bfbfbf;padding:200rpx0;box-sizing:border-box;}4.index.wxml如下使用:
!--index.wxml--viewclass='container'/viewPage小程序页面主要包含四个文件.js、.json、.wxml、.wxss5.小程序页面Page
6.小程序页面生命周期函数在.js文件中,其中包含有onLoad、onReady、onShow、onHide、onUnload生命周期函数等。官方文档
//index.jsPage({data:{text:"Thisispagedata."},onLoad:function(options){//Dosomeinitializewhenpageload.},onReady:function(){//Dosomethingwhenpageready.},onShow:function(){//Dosomethingwhenpageshow.},onHide:function(){//Dosomethingwhenpagehide.},onUnload:function(){//Dosomethingwhenpageclose.},onPullDownRefresh:function(){//Dosomethingwhenpulldown.},onReachBottom:function(){//Dosomethingwhenpagereachbottom.},onShareAppMessage:function(){//returncustomsharedatawhenusershare.},onPageScroll:function(){//Dosomethingwhenpagescroll},onTabItemTap(item){console.log(item.index)console.log(item.pagePath)console.log(item.text)},//Eventhandler.viewTap:function(){this.setData({text:'Setsomedataforupdatingview.'},function(){//thisissetDatacallback})},customData:{hi:'MINA'}})7.小程序页面视图
8.小程序页面编写在.wxml文件中,此处内容比较多,后期博文会对其一一介绍。官方文档
!--index.wxml--formbindsubmit='submit'view用户名:/viewinputtype='text'name="username"/inputview密码:/viewinputtype='text'password='true'name="password"/inputbuttonform-type='submit'登陆/button/form小程序页面配置json页面中.json文件主要是对页面标题栏,以及其他属性进行配置。官方文档{"navigationBarTitleText":"查看启动日志"}小程序页面样式wxss.wxss类似于css,页面展示样式控制。.log-list{display:flex;flex-direction:column;padding:40rpx;}.log-item{margin:10rpx;}













