constructor(props) { super(props); const detailSaveData = sessionStorageUtil.read('detailSaveData'); this.state = { indocno: this.props.location.state.indocno, type: this.props.location.state.type, selectedTab: detailSaveData ? detailSaveData.selectedTab : 0, data: {}, pathname: window.location.pathname, visibleModal: false, time: new Date(), } } 设置this.props.location.state.indocno为undfind时indocno为“”
时间: 2023-07-15 11:15:43 浏览: 95
this.$toast() 了解一下?
可以在 constructor 中添加一个判断语句,来避免出现 undefined 的情况,示例如下:
```
constructor(props) {
super(props);
const detailSaveData = sessionStorageUtil.read('detailSaveData');
const indocno = this.props.location.state.indocno || ""; // 添加判断语句
this.state = {
indocno: indocno,
type: this.props.location.state.type,
selectedTab: detailSaveData ? detailSaveData.selectedTab : 0,
data: {},
pathname: window.location.pathname,
visibleModal: false,
time: new Date(),
};
}
```
这样当 `this.props.location.state.indocno` 为 undefined 时,就会将 `indocno` 设置为空字符串。
阅读全文