mirror of
https://gitee.com/dcloud/uni-preset-vue
synced 2026-04-22 00:00:04 +08:00
chore: uni.promisify.adaptor.js
This commit is contained in:
@@ -1,32 +1,8 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
import './uni.promisify.adaptor'
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
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)))
|
const app = new (typeof App === 'function' ? App : Vue.extend(Object.assign({ mpType: 'app' }, App)))
|
||||||
app.$mount();
|
app.$mount();
|
||||||
|
|||||||
@@ -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 Vue from 'vue'
|
||||||
import App from './App'
|
import App from './App'
|
||||||
|
import './uni.promisify.adaptor'
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
App.mpType = 'app'
|
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({
|
const app = new Vue({
|
||||||
...App
|
...App
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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]));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user