Skip to content

Commit 18e03d0

Browse files
authored
Merge pull request #12167 from 2betop/fix-global-vars
fix: 修复全局变量初始化异常
2 parents e4ebc53 + d941147 commit 18e03d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/amis-core/src/RootRenderer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class RootRenderer extends React.Component<RootRendererProps> {
3939
this.store.updateContext(props.context, true);
4040
this.store.initData(props.data);
4141
this.store.updateLocation(props.location, this.props.env?.parseLocation);
42-
this.store.setGlobalVars(props.globalVars);
4342

4443
// 将数据里面的函数批量的绑定到 this 上
4544
bulkBindFunctions<RootRenderer /*为毛 this 的类型自动识别不出来?*/>(this, [
@@ -85,6 +84,9 @@ export class RootRenderer extends React.Component<RootRendererProps> {
8584
}
8685

8786
componentDidMount() {
87+
// 不要设置太早,否则组件内部的监控可能会监控不到,因为初始值可能在监控之前就设置了。
88+
// 以至于监控不到变化。
89+
this.store.setGlobalVars(this.props.globalVars);
8890
document.addEventListener(
8991
'visibilitychange',
9092
this.handlePageVisibilityChange

0 commit comments

Comments
 (0)