Javascript 用es6标准在redux中使用mixin的最佳方法是什么?
我只是一个刚开始学习React/Redux的孩子,这很酷。但es6标准不支持某些函数。是的,我看到了许多替代方法,但我无法获得它(使用高阶函数)。有没有帮助我在React es6代码中添加mixinJavascript 用es6标准在redux中使用mixin的最佳方法是什么?,javascript,reactjs,redux,mixins,Javascript,Reactjs,Redux,Mixins,我只是一个刚开始学习React/Redux的孩子,这很酷。但es6标准不支持某些函数。是的,我看到了许多替代方法,但我无法获得它(使用高阶函数)。有没有帮助我在React es6代码中添加mixin import React from 'react'; import Fetch from 'whatwg-fetch'; import jwt from 'jwt-simple'; import Reflux from 'reflux'; const secret
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;
从“React”导入React;
从“whatwg Fetch”导入Fetch;
从“jwt simple”导入jwt;
从“回流”导入回流;
const secret='goal';
类形式扩展了React.Component{
//混合:[
//es6中不支持
// ],
建造师(道具){
超级(道具);
此.state={
值:“”,
已发布:“”
}
}
邮政编码(e){
e、 预防默认值();
if(this.refs.email.value&&this.refs.name.value!=''){
常数数据={
电子邮件:this.refs.email.value,
名称:this.refs.name.value
};
const encodehead=jwt.encode(数据,秘密);
常量加密={
编码头
};
$.ajax({
键入:“POST”,
url:“/post”,
标题:{
科瓦姆:编码头
},
})
}
}
render(){
console.log(this.state);
返回(
电子邮件地址
名称
发送到服务器
)
}
}
导出默认表单;
您应该改为使用,因为在ES6类中不再使用mixin,请参阅。使用回流的ES6 API:
目前只从git repo本身(不是npm或任何东西)提供,但它工作得很好。你能自己编写一个带有高阶函数的代码示例并发布吗?这就是你的学习方式。我可以检查一下。好的,我会试试@leoBro,我拿不到。请把那个片段贴在这里,关于高阶组件