mirror of
https://gitee.com/dcloud/uni-preset-vue
synced 2025-04-09 23:33:10 +08:00
chore: uni.promisify.adaptor.js
This commit is contained in:
parent
4517f04736
commit
c8f557ec23
template
@ -1,32 +1,8 @@
|
||||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
import './uni.promisify.adaptor'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
function isPromise(obj: any) {
|
||||
return (
|
||||
!!obj &&
|
||||
(typeof obj === "object" || typeof obj === "function") &&
|
||||
typeof obj.then === "function"
|
||||
);
|
||||
}
|
||||
|
||||
uni.addInterceptor({
|
||||
returnValue(res: any) {
|
||||
if (!isPromise(res)) {
|
||||
return res;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
res.then((res: [any, any]) => {
|
||||
if (res[0]) {
|
||||
reject(res[0]);
|
||||
} else {
|
||||
resolve(res[1]);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const app = new (typeof App === 'function' ? App : Vue.extend(Object.assign({ mpType: 'app' }, App)))
|
||||
app.$mount();
|
||||
|
10
template/default-ts/uni.promisify.adaptor.ts
Normal file
10
template/default-ts/uni.promisify.adaptor.ts
Normal file
@ -0,0 +1,10 @@
|
||||
uni.addInterceptor({
|
||||
returnValue (res) {
|
||||
if (!(!!res && (typeof res === "object" || typeof res === "function") && typeof res.then === "function")) {
|
||||
return res;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
res.then((res: [unknown, unknown]) => res[0] ? reject(res[0]) : resolve(res[1]));
|
||||
});
|
||||
},
|
||||
});
|
@ -1,35 +1,11 @@
|
||||
import Vue from 'vue'
|
||||
import App from './App'
|
||||
import './uni.promisify.adaptor'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
App.mpType = 'app'
|
||||
|
||||
function isPromise(obj) {
|
||||
return (
|
||||
!!obj &&
|
||||
(typeof obj === "object" || typeof obj === "function") &&
|
||||
typeof obj.then === "function"
|
||||
);
|
||||
}
|
||||
|
||||
uni.addInterceptor({
|
||||
returnValue(res) {
|
||||
if (!isPromise(res)) {
|
||||
return res;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
res.then((res) => {
|
||||
if (res[0]) {
|
||||
reject(res[0]);
|
||||
} else {
|
||||
resolve(res[1]);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const app = new Vue({
|
||||
...App
|
||||
})
|
||||
|
10
template/default/uni.promisify.adaptor.js
Normal file
10
template/default/uni.promisify.adaptor.js
Normal file
@ -0,0 +1,10 @@
|
||||
uni.addInterceptor({
|
||||
returnValue (res) {
|
||||
if (!(!!res && (typeof res === "object" || typeof res === "function") && typeof res.then === "function")) {
|
||||
return res;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
res.then((res) => res[0] ? reject(res[0]) : resolve(res[1]));
|
||||
});
|
||||
},
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user