File tree Expand file tree Collapse file tree 5 files changed +113
-54
lines changed Expand file tree Collapse file tree 5 files changed +113
-54
lines changed Original file line number Diff line number Diff line change
1
+ // 注册一个小程序示例
2
+ App ( {
3
+ // 小程序初始化完成时
4
+ onLaunch : function ( options ) {
5
+ // 获取用户信息
6
+ console . log ( options )
7
+ } ,
8
+ // 小程序显示出来时
9
+ onShow : function ( options ) {
10
+ // 1.判断小程序的进入场景
11
+ console . log ( options )
12
+ switch ( options . scene ) {
13
+ case 1001 :
14
+ break ;
15
+ case 1005 :
16
+ break ;
17
+ }
18
+
19
+ // 2.获取用户的信息, 并且获取到用户信息之后, 将用户的信息传递给服务器
20
+ wx . getUserInfo ( {
21
+ success : function ( res ) {
22
+ console . log ( res )
23
+ }
24
+ } )
25
+ } ,
26
+ // 小程序隐藏时
27
+ onHide : function ( ) {
28
+
29
+ } ,
30
+ // 小程序产生一些错误
31
+ onError : function ( msg ) {
32
+
33
+ } ,
34
+ globalData : {
35
+ name : 'coderwhy' ,
36
+ age : 18
37
+ }
38
+ } )
Original file line number Diff line number Diff line change 1
1
// pages/home/home.js
2
- Page ( {
2
+ // getApp()获取App()产生的示例对象
3
+ // const app = getApp()
3
4
4
- /**
5
- * 页面的初始数据
6
- */
7
- data : {
5
+ // const name = app.globalData.name;
6
+ // const age = app.globalData.age;
8
7
8
+ // 注册一个页面
9
+ // 页面也有自己的生命周期函数
10
+ Page ( {
11
+ // ------------ 2.初始化数据 -------------------
12
+ data : {
13
+ message : '哈哈哈' ,
14
+ list : [ ]
9
15
} ,
10
16
11
- /**
12
- * 生命周期函数--监听页面加载
13
- */
14
- onLoad : function ( options ) {
15
-
17
+ // ------------ 1.监听页面的生命周期函数 -------------------
18
+ // 页面被加载出来
19
+ onLoad ( ) {
20
+ console . log ( 'onLoad' )
21
+ const _this = this ;
22
+ wx . request ( {
23
+ url : 'http://123.207.32.32:8000/recommend' ,
24
+ // 箭头函数中的this一层层向上找
25
+ success : function ( res ) {
26
+ console . log ( res )
27
+ const data = res . data . data . list ;
28
+ _this . setData ( {
29
+ list : data
30
+ } )
31
+ }
32
+ } )
16
33
} ,
17
-
18
- /**
19
- * 生命周期函数--监听页面初次渲染完成
20
- */
21
- onReady : function ( ) {
22
-
34
+ // 页面显示出来时
35
+ onShow ( ) {
36
+ console . log ( 'onShow' )
23
37
} ,
24
-
25
- /**
26
- * 生命周期函数--监听页面显示
27
- */
28
- onShow : function ( ) {
29
-
38
+ // 页面初次渲染完成时
39
+ onReady ( ) {
40
+ console . log ( 'onReady' )
30
41
} ,
31
-
32
- /**
33
- * 生命周期函数--监听页面隐藏
34
- */
35
- onHide : function ( ) {
36
-
42
+ // 当页面隐藏起来时
43
+ onHide ( ) {
44
+ console . log ( 'onHide' )
37
45
} ,
38
-
39
- /**
40
- * 生命周期函数--监听页面卸载
41
- */
42
- onUnload : function ( ) {
43
-
46
+ onUnload ( ) {
47
+ console . log ( 'onUnload' )
44
48
} ,
45
49
46
- /**
47
- * 页面相关事件处理函数--监听用户下拉动作
48
- */
49
- onPullDownRefresh : function ( ) {
50
-
50
+ // ------------ 3.监听wxml中相关的一些事件 -------------------
51
+ handleGetUserInfo ( event ) {
52
+ console . log ( event )
51
53
} ,
52
-
53
- /**
54
- * 页面上拉触底事件的处理函数
55
- */
56
- onReachBottom : function ( ) {
57
-
54
+ handleViewClick ( ) {
55
+ console . log ( '哈哈哈被点击了' )
58
56
} ,
59
57
60
- /**
61
- * 用户点击右上角分享
62
- */
63
- onShareAppMessage : function ( ) {
64
-
58
+ // ------------ 4.其他事件 -------------------
59
+ // 监听页面的滚动
60
+ onPageScroll ( obj ) {
61
+ // console.log(obj)
62
+ } ,
63
+ // 监听页面滚动到顶部
64
+ onReachBottom ( ) {
65
+ console . log ( '页面滚动到顶部' )
66
+ } ,
67
+ onPullDownRefresh ( ) {
68
+ console . log ( '下拉刷新的事件' )
65
69
}
66
- } )
70
+ } )
Original file line number Diff line number Diff line change 1
1
{
2
- "usingComponents" : {}
2
+ "usingComponents" : {},
3
+ "enablePullDownRefresh" : true
3
4
}
Original file line number Diff line number Diff line change 1
1
<!--pages/home/home.wxml-->
2
2
<text class='title'>Hello World</text>
3
3
<button size='mini'>按钮</button>
4
+
5
+ <!-- 2.获取用户信息的方式 -->
6
+ <button size='mini'
7
+ open-type='getUserInfo'
8
+ bindgetuserinfo='handleGetUserInfo'>
9
+ 获取授权
10
+ </button>
11
+
12
+ <!-- 3.展示用户信息的方法 -->
13
+ <open-data type="userNickName"></open-data>
14
+ <open-data type="userAvatarUrl"></open-data>
15
+
16
+ <view bindtap='handleViewClick'>{{message}}</view>
17
+
18
+ <view wx:for="{{list}}">{{item.title}}</view>
Original file line number Diff line number Diff line change 4
4
"ignore" : []
5
5
},
6
6
"setting" : {
7
- "urlCheck" : true ,
7
+ "urlCheck" : false ,
8
8
"es6" : true ,
9
9
"postcss" : true ,
10
10
"minified" : true ,
11
11
"newFeature" : true ,
12
- "autoAudits" : false
12
+ "autoAudits" : false ,
13
+ "checkInvalidKey" : true
13
14
},
14
15
"compileType" : " miniprogram" ,
15
16
"libVersion" : " 2.7.1" ,
You can’t perform that action at this time.
0 commit comments