错误提示
Error: Passing callbacks to saveXML is deprecated and will be removed in a future major release。
Please switch to promises: https://bpmn.io/l/moving-to-promises.html
原因
简单来说,就是要将回调函数改为 Promise 异步操作。
之前回调写法
import BpmnModeler from 'bpmn-js/lib/Modeler';
const modeler = new BpmnModeler();
modeler.importXML(bpmnXmlStr, (err, warnings) => {
// ...
});
现在地异步写法
import BpmnModeler from 'bpmn-js/lib/Modeler';
const modeler = new BpmnModeler();
try {
const result = await modeler.importXML(bpmnXmlStr);
const { warnings } = result;
console.log(warnings);
} catch (err) {
console.log(err.message, err.warnings);
}
注意
Parsing error: Can not use keyword ‘await’ outside an async function
用了 await
之后需要和 async
搭配使用