0

我正在请求一个 api 来响应 mongodb,例如这是我的构造函数

    constructor(){
        super();
        this.state={
            email:'',
            eemail:'',
            password:'',
            epassword:'',
            mobile:'',
            emobile:'',
            isadmin:'yes',
            isprinter:'yes',
            isuser:'yes',
        }
    }

并像这样在表单提交函数中调用api

    formSubmit(e){
        e.preventDefault();
        let error=0;
        if(this.state.email===''){
            this.setState({eemail:"This field is require"})
            error=1
        }
        if(!error){
            console.log(this.state)
            const admin = {
              email: this.state.email,
              password: this.state.password,
              mobile: this.state.mobile,
              isadmin: this.state.isadmin,
              isuser: this.state.isuser,
              isprinter: this.state.isprinter,
            }

            axios.post("http://localhost:5000/admin/add",admin)
            .then(res=>console.log(res))
        }
    }

它给了我

错误:ValidationError:isuser:isuser需要路径。,isprinter:需要路径isprinter。,isadmin:isadmin需要路径。即使我正在传递所有这些参数。我也尝试过 true 而不是 yes 并且我在 mongodb 模型中有 String 数据类型

4

0 回答 0