重新加载窗口
This commit is contained in:
@@ -4,29 +4,42 @@ import { cloneDeep } from 'lodash'
|
||||
export default class ComponentDynamic extends Component {
|
||||
|
||||
state = {
|
||||
key: null,
|
||||
component: null
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
let c;
|
||||
shouldComponentUpdate() {
|
||||
if (this.props.onRef) {
|
||||
this.props.onRef(this)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadComponent()
|
||||
}
|
||||
|
||||
async loadComponent() {
|
||||
let component;
|
||||
|
||||
try {
|
||||
if (this.props.is) {
|
||||
if (this.props.is.constructor === Function) {
|
||||
// 导入函数
|
||||
c = await this.props.is()
|
||||
component = await this.props.is()
|
||||
} else {
|
||||
// 导入路径,必须是src以下节点,如 pages/home
|
||||
c = await import(`../../${this.props.is}`)
|
||||
component = await import(`../../${this.props.is}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
c = await import(`views/error/404`)
|
||||
} catch {
|
||||
component = await import(`views/error/404`)
|
||||
}
|
||||
|
||||
this.setState({
|
||||
component: c.default
|
||||
key: Math.random().toString(16).slice(2),
|
||||
component: component.default
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,10 +49,9 @@ export default class ComponentDynamic extends Component {
|
||||
|
||||
delete props.is
|
||||
|
||||
return (<>
|
||||
{
|
||||
this.state.component && <this.state.component {...props} />
|
||||
}
|
||||
</>)
|
||||
if (this.state.component) {
|
||||
return <this.state.component key={this.state.key} {...props} />
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user