修复报错'

This commit is contained in:
liaoxuezhi 2019-11-24 13:39:24 +08:00
parent 46ba154e5a
commit 4308570905
2 changed files with 20 additions and 8 deletions

View File

@ -224,6 +224,7 @@ export class ToastMessage extends React.Component<ToastMessageProps> {
// content: React.RefObject<HTMLDivElement>;
timer: NodeJS.Timeout;
mounted: boolean = false;
constructor(props: ToastMessageProps) {
super(props);
@ -234,16 +235,18 @@ export class ToastMessage extends React.Component<ToastMessageProps> {
this.close = this.close.bind(this);
}
componentWillUnmount() {
clearTimeout(this.timer);
}
componentDidMount() {
this.mounted = true;
this.setState({
visible: true
});
}
componentWillUnmount() {
clearTimeout(this.timer);
this.mounted = false;
}
handleMouseEnter() {
clearTimeout(this.timer);
}
@ -254,7 +257,9 @@ export class ToastMessage extends React.Component<ToastMessageProps> {
handleEntered() {
const timeOut = this.props.timeOut;
this.timer = setTimeout(this.close, timeOut);
if (this.mounted) {
this.timer = setTimeout(this.close, timeOut);
}
}
close() {

View File

@ -1,4 +1,11 @@
import {types, getParent, SnapshotIn, flow, getRoot} from 'mobx-state-tree';
import {
types,
getParent,
SnapshotIn,
flow,
getRoot,
hasParent
} from 'mobx-state-tree';
import {IFormStore} from './form';
import {str2rules, validate as doValidate} from '../utils/validations';
import {Api, Payload, fetchOptions} from '../types';
@ -59,11 +66,11 @@ export const FormItemStore = types
})
.views(self => {
function getForm(): any {
return getParent(self, 2);
return hasParent(self, 2) ? getParent(self, 2) : null;
}
function getValue(): any {
return getForm().getValueByName(self.name);
return getForm() ? getForm().getValueByName(self.name) : undefined;
}
function getLastOptionValue(): any {