装饰器解决按钮、表单重复提交 发表于 2018-12-10 | | 阅读次数 | 1234567891011121314151617181920212223242526272829303132export function HandleAsyncOperate(name?) { return function ( target: any, key: string, descriptor: TypedPropertyDescriptor<Function> ) { let func = descriptor.value; let flag = false; console.log(arguments, "HandleFormSubmit"); descriptor.value = async function (...args) { console.log(flag, 'before func.call') if (flag) { console.log('flag true return false') return false; } flag = true; await func.call(this, ...args); flag = false; console.log(flag, 'after func.call') }; };}// 方式一@HandleAsyncOperate()async asyncOpertate() { await new Ajax(...)}// 方式二@HandleAsyncOperate() asyncOpertate() { return new Promise(...)} 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏 支付宝打赏