使用Wordpress Rest API反应本地用户注册

时间:2019-06-25 07:33:42

标签: react-native wordpress-rest-api

我是React Native的新手。我想在我的wordpress网站中添加用户。所以我已经在服务器上安装了一个WordPress站点。在我的React本机应用程序中,我已经完成了“注册”页面并实现了如下所示的Rest API。

export default class RegisterForm extends Component<{}> {
  // For store the user data
  constructor(props){
      super(props)
      this.state = {
        UserName: "",
        UserEmail:"",
        UserPassword:""
      }
  }
  userRegister = () => {
    const { UserName } = this.state;
    const { UserEmail } = this.state;
    const { UserPassword } = this.state;

    fetch('mysiteURL/wetest/wp-json/wp/v2/users/', {
        method: 'post',
        header:{
          'Accept': 'application/json',
          'Content-type': 'application/json'
        },
        body:JSON.stringify({
          username: UserName,
          email: UserEmail,
          password: UserPassword,
        })      
    })
    .then((response) => response.json())
      .then((responseJson) =>{
        alert(responseJson);
      })
      .catch((error)=>{
        console.error(error);
    });
  }
    render(){
        return(
            <View style={styles.container}>
          <TextInput style={styles.inputBox} 
              underlineColorAndroid='rgba(0,0,0,0)' 
              placeholder="Name"
              placeholderTextColor = "#ffffff"
              selectionColor="#fff"
              onSubmitEditing={()=> this.password.focus()}
              onchangeText = { UserName  => this.setState({UserName})}
              />
          <TextInput style={styles.inputBox} 
              underlineColorAndroid='rgba(0,0,0,0)' 
              placeholder="Email"
              placeholderTextColor = "#ffffff"
              selectionColor="#fff"
              keyboardType="email-address"
              onSubmitEditing={()=> this.password.focus()}
              onchangeText = { UserEmail  => this.setState({UserEmail})}
              />
          <TextInput style={styles.inputBox} 
              underlineColorAndroid='rgba(0,0,0,0)' 
              placeholder="Password"
              secureTextEntry={true}
              placeholderTextColor = "#ffffff"
              ref={(input) => this.password = input}
              onchangeText = { UserPassword  => this.setState({UserPassword})}
              />  
           <TouchableOpacity style={styles.button} onPress={this.userRegister}>
             <Text style={styles.buttonText} >Register</Text>
           </TouchableOpacity>     
        </View>
            )
    }
}

但是在点击注册按钮后,它会发出类似[[object object]].

的警告消息

有什么我想念的吗?请帮忙。预先感谢。

0 个答案:

没有答案