export const state = {
"loginInfo": {
"userName": '',
"userPassword": '',
"remember": false
},
};
export function _setval(_this, e) {
// _this是jsx页面传过来的this,否则使用不了this.setState
// e也是jsx页面传参过来的
let value = e.target.value;
let name = e.target.name;
let { loginInfo } = state
loginInfo[name] = value
_this.setState({
loginInfo
})
}
jsx文件
import React, { Component } from 'react';
import {state,_setval} from '../../commonJS/index'; //引入js文件
export default class index extends Component {
render() {
return (
<React.Fragment >
<ant.Input name="userName" onChange={(e)=>{_setval(this,e)}} value={state.loginInfo.userName} }></ant.Input>
<ant.Input.Password name="userPassword" onChange={(e)=>{_setval(this,e)}} value={state.loginInfo.userPassword} }></ant.Input.Password>
</React.Fragment >
)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)