Javascript 反应条纹元素得到;无法读取属性';道具';“未定义”的定义;
下面是react条带元素在自述文件中的示例。我可以正确设置条带表单,但按下“付款”按钮时出现以下错误Javascript 反应条纹元素得到;无法读取属性';道具';“未定义”的定义;,javascript,reactjs,stripe.js,react-stripe-elements,Javascript,Reactjs,Stripe.js,React Stripe Elements,下面是react条带元素在自述文件中的示例。我可以正确设置条带表单,但按下“付款”按钮时出现以下错误 Uncaught TypeError: Cannot read property 'props' of undefined at handleSubmit (paymentForm.jsx?9f51:10) at HTMLUnknownElement.callCallback (react-dom.development.js?cada:540) at Object.in
Uncaught TypeError: Cannot read property 'props' of undefined
at handleSubmit (paymentForm.jsx?9f51:10)
at HTMLUnknownElement.callCallback (react-dom.development.js?cada:540)
at Object.invokeGuardedCallbackDev (react-dom.development.js?cada:579)
at Object.invokeGuardedCallback (react-dom.development.js?cada:436)
....
我的paymentForm.jsx如下所示:
从“React”导入React;
从'react stripe elements'导入{injectStripe}
从“./PaymentCard”导入PaymentCard
class PaymentForm extends React.Component {
handleSubmit(ev) {
ev.preventDefault();
this.props.stripe.createToken({name: 'Jenny Rosen'}).then(({token}) => {
console.log('Received Stripe token:', token);
});
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<PaymentCard />
<button>Pay</button>
</form>
)
}
}
export default injectStripe(PaymentForm);
class PaymentForm扩展了React.Component{
可装卸货物(ev){
ev.preventDefault();
this.props.stripe.createToken({name:'Jenny Rosen'})。然后({token})=>{
log('收到的条带标记:',标记);
});
}
render(){
返回(
支付
)
}
}
导出默认条带(PaymentForm);
通过将函数绑定到类来解决Ok问题
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this)
}
尝试添加super(道具)构造函数属性中的代码>