File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616 <view class =" page-body-buttons" >
1717 <block v-if =" playing" >
1818 <view class =" page-body-button" @tap =" stop" >
19- <image src =" ../../.. /static/stop.png" ></image >
19+ <image src =" /static/stop.png" ></image >
2020 </view >
2121 <view class =" page-body-button" @tap =" pause" >
22- <image src =" ../../.. /static/pause.png" ></image >
22+ <image src =" /static/pause.png" ></image >
2323 </view >
2424 </block >
2525 <block v-if =" !playing" >
2626 <view class =" page-body-button" ></view >
2727 <view class =" page-body-button" @tap =" play" >
28- <image src =" ../../.. /static/play.png" ></image >
28+ <image src =" /static/play.png" ></image >
2929 </view >
3030 </block >
3131 <view class =" page-body-button" ></view >
Original file line number Diff line number Diff line change 99 <textarea :value =" res" ></textarea >
1010 </view >
1111 <view class =" uni-btn-v uni-common-mt" >
12- <button type =" primary" @click =" sendRequest" :loading =" loading" >发起请求</button >
12+ <button type =" primary" @click =" sendRequest" :loading =" loading" >发起请求(Callback)</button >
13+ <button type =" primary" @click =" sendRequest('promise')" :loading =" loading" >发起请求(Promise)</button >
14+ <button type =" primary" @click =" sendRequest('await')" :loading =" loading" >发起请求(Async/Await)</button >
1315 </view >
1416 </view >
1517 </view >
2628 }
2729 },
2830 methods: {
29- sendRequest : function () {
30- this .loading = true
31+ sendRequest (mode ) {
32+ this .loading = true ;
33+ switch (mode) {
34+ case ' promise' :
35+ this ._requestPromise ();
36+ break ;
37+ case ' await' :
38+ this ._requestAwait ();
39+ break ;
40+ default :
41+ this ._request ();
42+ break ;
43+ }
44+ },
45+ _request () {
3146 uni .request ({
3247 url: requestUrl,
3348 dataType: ' text' ,
5570 this .loading = false ;
5671 }
5772 });
73+ },
74+ _requestPromise () {
75+ uni .request ({
76+ url: requestUrl,
77+ dataType: ' text' ,
78+ data: {
79+ noncestr: Date .now ()
80+ }
81+ }).then (res => {
82+ console .log (' request success' , res[1 ]);
83+ uni .showToast ({
84+ title: ' 请求成功' ,
85+ icon: ' success' ,
86+ mask: true ,
87+ duration: duration
88+ });
89+ this .res = ' 请求结果 : ' + JSON .stringify (res[1 ]);
90+
91+ this .loading = false ;
92+ }).catch (err => {
93+ console .log (' request fail' , err);
94+ uni .showModal ({
95+ content: err .errMsg ,
96+ showCancel: false
97+ });
98+
99+ this .loading = false ;
100+ });
101+ },
102+ async _requestAwait () {
103+ const [err , res ] = await uni .request ({
104+ url: requestUrl,
105+ dataType: ' text' ,
106+ data: {
107+ noncestr: Date .now ()
108+ }
109+ });
110+ if (err) {
111+ console .log (' request fail' , err);
112+ uni .showModal ({
113+ content: err .errMsg ,
114+ showCancel: false
115+ });
116+ } else {
117+ console .log (' request success' , res)
118+ uni .showToast ({
119+ title: ' 请求成功' ,
120+ icon: ' success' ,
121+ mask: true ,
122+ duration: duration
123+ });
124+ this .res = ' 请求结果 : ' + JSON .stringify (res);
125+ }
126+ this .loading = false ;
58127 }
59128 }
60129 }
You can’t perform that action at this time.
0 commit comments