Skip to content

Commit 24d4168

Browse files
committed
fix: vue3 promise data change
1 parent 2d0e0d5 commit 24d4168

File tree

4 files changed

+74
-17
lines changed

4 files changed

+74
-17
lines changed

pages/API/login/login.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,24 @@
249249
})
250250
},
251251
async loginByApple(provider, res) {
252-
// 获取用户信息
253-
const [getUserInfoErr, result] = await uni.getUserInfo({
252+
// 获取用户信息
253+
let getUserInfoErr, result
254+
// #ifndef VUE3
255+
[getUserInfoErr, result] = await uni.getUserInfo({
254256
provider
255-
});
257+
});
258+
// #endif
259+
260+
// #ifdef VUE3
261+
try {
262+
result = await uni.getUserInfo({
263+
provider
264+
});
265+
} catch(e) {
266+
getUserInfoErr = e
267+
}
268+
// #endif
269+
256270
if (getUserInfoErr) {
257271
let content = getUserInfoErr.errMsg;
258272
if (~content.indexOf('uni.login')) {

pages/API/request/request.vue

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
}
7272
});
7373
},
74-
_requestPromise() {
74+
_requestPromise() {
75+
// #ifndef VUE3
7576
uni.request({
7677
url: requestUrl,
7778
dataType: 'text',
@@ -87,7 +88,6 @@
8788
duration: duration
8889
});
8990
this.res = '请求结果 : ' + JSON.stringify(res[1]);
90-
9191
this.loading = false;
9292
}).catch(err => {
9393
console.log('request fail', err);
@@ -97,16 +97,62 @@
9797
});
9898
9999
this.loading = false;
100-
});
100+
});
101+
// #endif
102+
103+
// #ifdef VUE3
104+
uni.request({
105+
url: requestUrl,
106+
dataType: 'text',
107+
data: {
108+
noncestr: Date.now()
109+
}
110+
}).then(res => {
111+
console.log('request success', res);
112+
uni.showToast({
113+
title: '请求成功',
114+
icon: 'success',
115+
mask: true,
116+
duration: duration
117+
});
118+
this.res = '请求结果 : ' + JSON.stringify(res);
119+
120+
this.loading = false;
121+
}).catch(err => {
122+
console.log('request fail', err);
123+
uni.showModal({
124+
content: err.errMsg,
125+
showCancel: false
126+
});
127+
128+
this.loading = false;
129+
});
130+
// #endif
101131
},
102-
async _requestAwait() {
103-
const [err, res] = await uni.request({
132+
async _requestAwait() {
133+
let res, err
134+
// #ifndef VUE3
135+
[err, res] = await uni.request({
104136
url: requestUrl,
105137
dataType: 'text',
106138
data: {
107139
noncestr: Date.now()
108140
}
109-
});
141+
});
142+
// #endif
143+
// #ifdef VUE3
144+
try {
145+
res = await uni.request({
146+
url: requestUrl,
147+
dataType: 'text',
148+
data: {
149+
noncestr: Date.now()
150+
}
151+
});
152+
} catch(e){
153+
err=e
154+
}
155+
// #endif
110156
if (err) {
111157
console.log('request fail', err);
112158
uni.showModal({

pages/tabBar/component/component.nvue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@
8080
open: false,
8181
pages: [
8282
'image',
83-
'video',
84-
// #ifndef MP-ALIPAY || MP-TOUTIAO || VUE3
85-
'audio',
86-
// #endif
83+
'video'
8784
],
8885
},
8986
// #ifndef MP-TOUTIAO

pages/tabBar/template/template.nvue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979
url: 'component-communication'
8080
},
8181
// #ifndef MP-QQ || QUICKAPP-WEBVIEW
82-
{
83-
name: 'uCharts 图表',
84-
url: 'ucharts'
85-
},
82+
// {
83+
// name: 'uCharts 图表',
84+
// url: 'ucharts'
85+
// },
8686
// #endif
8787
// #ifndef QUICKAPP-WEBVIEW
8888
{

0 commit comments

Comments
 (0)