这里我有一个联系表单,我希望提交表单后表单的所有值都应该为空。
我编写了以下代码。但是在提交表单的值保持不变后,这不起作用。
这里有什么问题以及如何解决它。
export default function contact() {
const[name,setName]=useState("")
const[phone,setPhone]=useState("")
const[email,setEmail]=useState("")
const[query,setQuery]=useState("")
const [submitted, setSubmitted] = useState(false)
const handleSubmit=(e)=>{
e.preventDefault()
console.log(e);
let data = {
name,
email,
phone,
query
}
console.log(data);
axios.post('http://127.0.0.1:8000/api/create/',data).then((res)=>{
console.log(res);
setSubmitted(true)
setName('')
setPhone('')
setEmail('')
setQuery('')
})
}
return (
<>
<div>
<h1>Contact Page</h1>
</div>
<div >
<form action="contact" method="post">
<input name="name" onChange={(e)=>{setName(e.target.value)}} placeholder="Name" / ><br />
<input name="phone" onChange={(e)=>{setPhone(e.target.value)}} placeholder="Phone" /><br />
<input name="email" onChange={(e)=>{setEmail(e.target.value)}} type="email" placeholder="E-mail" / ><br />
<textarea name="text" onChange={(e)=>{setQuery(e.target.value)}} placeholder="How can we help …Run Code Online (Sandbox Code Playgroud) I just go through an interview where i was asked how can i access local variable of function to other function. code flow-
class A{
public:
void fun1(int a){
int local_var=a;
}
void fun2(){
// here i want to use local_var of fun1
//you are not allowed to do any changes either in fun1 and class
// however you can do anythingh in fun2.
}
}
Run Code Online (Sandbox Code Playgroud)
is there any way to do it.