当前位置: 代码迷 >> 综合 >> Promise 的使用,调用当前组件的this的时候的使用方法
  详细解决方案

Promise 的使用,调用当前组件的this的时候的使用方法

热度:88   发布时间:2024-01-04 14:56:11.0
const params = {operType:'3',//发布人改派reason:sendDesc,sendStaff:this.state.selectChangeMan,workId:workId,attachFiles:attachFiles,
};
// console.log('最终提交的信息====',params);
let component = this;//在promise中,this的含义已经改变,所以需要通过别名的方法将this引进来
Modal.confirm({title: '确定将此工单改派给 '+ this.state.selectChangeMan + ' 吗?',icon: <ExclamationCircleOutlined />,onOk() {let prom =  new Promise((resolve, reject) => {submitSendPublish(params).then((resinfo)=> {//异步加载数据。发布人改派// console.log('改派返回的信息',resinfo);try{if(resinfo.code==="00"){message.success('改派成功');resolve('success');//为then返回成功的参数,返回的值是success}else{reject('fail');//为then返回失败的参数,返回的值是failmessage.error('改派失败,',resinfo.msg);}}catch (e) {reject('error');console.log('改派失败===',e);message.error('改派失败');}});}).catch((error) => console.log('Promise errors!'+ error));prom.then((res) => {if(res === 'success'){component.close(false);history.back();//改派}else if(res === 'fail'){console.log('失败',res);}});return prom;//控件必须返回Promise对象。},onCancel() {},
});