react 组件的继承,这个错误怎么改?

import React from 'react'

import BaseWin from './baseWindow'

class Win extends BaseWin{
    constructor(props){
        super(props);
        this.state ={
            ...this.props
        };
        console.log(this.name);
        this.common();
    }

    getData(){
        return this.state;
    }

    render(){
        this.state.node.model.set({name:'zhongxia', age:17})
        return(
            <div className="pop-dialog">
                <h2>弹框1</h2>
                <form>
                    <label htmlFor="">用户名:</label><input value={this.state.name} type="text"/>
                    <label htmlFor="">密码:</label><input type="password" value={this.state.password}/>
                </form>
            </div>
        );

    }
}
export default Win;
import React from 'react'
/**
 * 所有弹框的基类
 */
class BaseWin extends React.Component{
    constructor(props){
        super(props);
        this.name ='zhongxia';
        this.state ={};
    }
    common(){
        alert('this is a common function!')
    }
}

export default BaseWin;

图片描述

阅读 2.6k
2 个回答

this.state.node是undefined, 传入的props有这个node参数吗?

在constructor中要用props而不是this.props

this.state ={
    ...props
};
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题