我试图创建一个全局函数页面,以便我可以重用我的代码。但是,我收到错误并想知道为什么这是未定义的。
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
}
最佳答案
您正在全局函数中使用this.props
。 this
未定义,因为您不在类(class)中。
关于javascript - 无法读取导出函数中未定义的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60805230/