mirror of
https://gitee.com/dcloud/uni-preset-vue
synced 2025-05-14 07:04:04 +08:00
chore: vue2 模板添加 Promisify 处理
This commit is contained in:
parent
b988dc8fd3
commit
6f3f68985a
@ -3,5 +3,30 @@ import App from './App.vue'
|
|||||||
|
|
||||||
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();
|
||||||
|
@ -5,6 +5,31 @@ 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
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user