修饰器

function arrest(target, calleeName, descriptor) {
        let oriFunc = descriptor.value;
        descriptor.value = function(...args){
            return Promise.resolve(oriFunc.apply(this, args))
                .then(res =>{
                    return Promise.resolve([null, res]);
                })
                .catch(err => {
                    return [err, null];
                });
        };
    };

@arrest()
async postFormId({habitID, type, formId}) {
    return await wx.$api.util.postFormId({habitID, type, formId});
},

  

原文地址:https://www.cnblogs.com/smzd/p/10340768.html