Skip to content

Commit

Permalink
延时函数解决setstate异步
Browse files Browse the repository at this point in the history
  • Loading branch information
lingxiaoyi committed Sep 24, 2019
1 parent 88bfbb9 commit d93cce8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ class App extends React.Component {
currentOptionArr = this.currentOptionArr;
}
let { css } = currentOptionArr[index];
//console.log('css', css);
let {
width,
height,
Expand Down Expand Up @@ -1066,6 +1067,12 @@ ${json.plain(this.finallObj).replace(/px/g, 'px')}
}
confirmImportCode() {
let canvas_sprite = this.canvas_sprite;
//延时函数 解决setstate异步加载问题
const delay = ms =>
new Promise(resolve => {
clearTimeout(this.delayT);
this.delayT = setTimeout(resolve, ms);
});
canvas_sprite.loadFromJSON(this.state.importCodeJson, async () => {
this.setState({
visibleImportCode: false
Expand All @@ -1075,6 +1082,7 @@ ${json.plain(this.finallObj).replace(/px/g, 'px')}
const element = Objects[index];
this.activeObject = element;
this.changeActiveObjectValue();
await delay(0);
await this.updateObject();
}
this.setState({
Expand Down Expand Up @@ -1422,7 +1430,6 @@ ${json.plain(this.finallObj).replace(/px/g, 'px')}
{!_.isArray(optionArr[i].css[item2]) && item2 === 'text' && (
<TextArea
defaultValue={item.css[item2]}
value={item.css[item2]}
onChange={event => {
let currentOptionArr = _.cloneDeep(this.state.currentOptionArr);
currentOptionArr[i].css[item2] = event.target.value;
Expand Down

0 comments on commit d93cce8

Please sign in to comment.