mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复 tpl 渲染时序问题导致的渲染错误 (#11016)
This commit is contained in:
parent
94ebe12715
commit
f1d75921b7
@ -73,6 +73,7 @@ export class Tpl extends React.Component<TplProps, TplState> {
|
|||||||
|
|
||||||
dom: any;
|
dom: any;
|
||||||
mounted: boolean;
|
mounted: boolean;
|
||||||
|
sn: number = 0;
|
||||||
|
|
||||||
constructor(props: TplProps) {
|
constructor(props: TplProps) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -102,7 +103,13 @@ export class Tpl extends React.Component<TplProps, TplState> {
|
|||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
async updateContent() {
|
async updateContent() {
|
||||||
|
let sn = ++this.sn;
|
||||||
const content = await this.getAsyncContent();
|
const content = await this.getAsyncContent();
|
||||||
|
|
||||||
|
// 解决异步时序问题,防止较早的运算覆盖较晚的运算结果
|
||||||
|
if (sn !== this.sn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.mounted && this.setState({content});
|
this.mounted && this.setState({content});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user