我只是一個學習React/Redux的新孩子,它非常酷。但是一些函數不支持es6標準。是的,我看到了很多替代方法但我無法獲得它(使用高階函數)。任何幫助對混入添加到我的陣營ES6代碼在es6標準中使用mixin的最佳方式是什麼?
import React from 'react';
import Fetch from 'whatwg-fetch';
import jwt from 'jwt-simple';
import Reflux from 'reflux';
const secret = 'goal';
class Form extends React.Component{
// mixins:[
// Not supported in es6
// ],
constructor(props){
super(props);
this.state = {
value:'',
posted:''
}
}
onPost(e){
e.preventDefault();
if(this.refs.email.value && this.refs.name.value != ''){
const data = {
email:this.refs.email.value,
name:this.refs.name.value
};
const encodehead = jwt.encode(data,secret);
const encrypt = {
encode:encodehead
};
$.ajax({
type: 'POST',
url: '/post',
headers: {
kovam: encodehead
},
})
}
}
render(){
console.log(this.state);
return (
<div>
<form className="postform" onSubmit={this.onPost.bind(this)}>
<label>Email Addres</label>
<input type="email" ref="email" className="form-control"/>
<label>Name</label>
<input type="text" ref="name" className="form-control"/>
<br/>
<br/>
<button type="submit" className="btn btn-primary">Post To server</button>
</form>
</div>
)
}
}
export default Form;
你可以爲這個代碼寫一個高階函數的例子嗎 – Nane
你自己試一試併發布 - 這就是你學習的方式。那我可以檢查一下。 – lustoykov
好吧,我會試試@leo – Nane