我试图创建一个全局函数页面,以便可以重用我的代码。但是,我遇到一个错误,并且想知道为什么未定义。
function clickUserProfile(id){
console.log(this);
if(id !== this.props.match.params.id){
this.props.history.push('/profile/' + id);
}
}
export function test(){
//code
serprofilepic.onclick = () => clickUserProfile(user_id);
//code
}
答案 0 :(得分:1)
您正在全局函数中使用this.props
。 this
未定义,因为您不在课程中。