class TransitionComp extends Component{
Duration = ()=>{
return Math.floor(Math.random() * Math.floor(3000))
}
render(){
console.log(this.Duration)
return(
)
}
}
控制台正在返回
ƒ () {
return Math.floor(Math.random() * Math.floor(3000));
}
而不是整数。如果我不使用“this”,则持续时间将变为未定义。
答案 0 :(得分:2)
调用该函数的正确方法是:
console.log(this.Duration());