File tree Expand file tree Collapse file tree 4 files changed +82
-61
lines changed Expand file tree Collapse file tree 4 files changed +82
-61
lines changed Original file line number Diff line number Diff line change 2
2
"pages" : [
3
3
" pages/home/home" ,
4
4
" pages/about/about"
5
- ]
5
+ ],
6
+ "sitemapLocation" : " sitemap.json"
6
7
}
Original file line number Diff line number Diff line change 1
1
// pages/home/home.js
2
- Page ( {
2
+ import request from '../../service/network.js'
3
3
4
- /**
5
- * 页面的初始数据
6
- */
4
+ Page ( {
7
5
data : {
8
6
9
7
} ,
10
-
11
- /**
12
- * 生命周期函数--监听页面加载
13
- */
14
8
onLoad : function ( options ) {
15
-
16
- } ,
17
-
18
- /**
19
- * 生命周期函数--监听页面初次渲染完成
20
- */
21
- onReady : function ( ) {
22
-
23
- } ,
24
-
25
- /**
26
- * 生命周期函数--监听页面显示
27
- */
28
- onShow : function ( ) {
29
-
30
- } ,
31
-
32
- /**
33
- * 生命周期函数--监听页面隐藏
34
- */
35
- onHide : function ( ) {
36
-
37
- } ,
38
-
39
- /**
40
- * 生命周期函数--监听页面卸载
41
- */
42
- onUnload : function ( ) {
43
-
44
- } ,
45
-
46
- /**
47
- * 页面相关事件处理函数--监听用户下拉动作
48
- */
49
- onPullDownRefresh : function ( ) {
50
-
51
- } ,
52
-
53
- /**
54
- * 页面上拉触底事件的处理函数
55
- */
56
- onReachBottom : function ( ) {
57
-
58
- } ,
59
-
60
- /**
61
- * 用户点击右上角分享
62
- */
63
- onShareAppMessage : function ( ) {
64
-
9
+ // 1.原生的方式发送网络请求
10
+ this . get_data_origin ( )
11
+
12
+ // 2.使用封装的request发送网络请求
13
+ // Promise最大的好处就是防止出现回调地狱
14
+ request ( {
15
+ url : 'http://123.207.32.32:8000/recommend'
16
+ } ) . then ( res => {
17
+ console . log ( res )
18
+ } ) . catch ( err => {
19
+ console . log ( err )
20
+ } )
21
+ } ,
22
+ get_data_origin ( ) {
23
+ // 发送网络请求
24
+ // 1.发送最简单的get请求
25
+ // wx.request({
26
+ // url: 'http://123.207.32.32:8000/recommend',
27
+ // success: function(res) {
28
+ // console.log(res)
29
+ // }
30
+ // })
31
+ // 2.get请求,并且携带参数
32
+ // wx.request({
33
+ // url: 'http://123.207.32.32:8000/home/data',
34
+ // data: {
35
+ // type: 'sell',
36
+ // page: 1
37
+ // },
38
+ // success: function (res) {
39
+ // console.log(res)
40
+ // }
41
+ // })
42
+ // 3.post请求,并且携带参数
43
+ // wx.request({
44
+ // url: 'http://httpbin.org/post',
45
+ // method: 'post',
46
+ // data: {
47
+ // name: 'coderwhy',
48
+ // age: 18
49
+ // },
50
+ // success: function(res) {
51
+ // console.log(res)
52
+ // },
53
+ // fail: function(err) {
54
+ // console.log(err)
55
+ // }
56
+ // })
65
57
}
66
58
} )
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" ,
Original file line number Diff line number Diff line change
1
+ export default function request ( options ) {
2
+ return new Promise ( ( resolve , reject ) => {
3
+ wx . request ( {
4
+ url : options . url ,
5
+ method : options . method || 'get' ,
6
+ data : options . data || { } ,
7
+ success : resolve ,
8
+ fail : reject
9
+ } )
10
+ } )
11
+ }
12
+
13
+ // export default function request(options) {
14
+ // return new Promise((resolve, reject) => {
15
+ // wx.request({
16
+ // url: options.url,
17
+ // method: options.method || 'get',
18
+ // data: options.data || {},
19
+ // success: function (res) {
20
+ // resolve(res)
21
+ // },
22
+ // fail: function (err) {
23
+ // reject(err)
24
+ // }
25
+ // })
26
+ // })
27
+ // }
You can’t perform that action at this time.
0 commit comments