javascript - Reactjs:使用javascript删除输入标签值
问题描述
当我单击按钮时,函数createPost工作,我的数据正确地发送到服务器。但输入值不会删除。
//...existing code...
createPost=()=>{
var url = 'http://127.0.0.1:8000/myapi/createpost/'
fetch(url,{
method:'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Token '+this.props.token,
},
body:JSON.stringify({
'body':this.state.body
})
})
.then((response)=>{
response.json()
document.getElementById("asif").value=''
this.setState({body:''})
this.props.rerender()
})
}
//...code...
<div className="rest container">
<p>
<input id="asif" onChange={(e)=>{this.setState({body:e.target.value})}}
style={{width:'100%', height:'36px', borderRadius:'25px'}}
placeholder={"What's on your mind, "+this.props.userdata.firstname+"?"} />
</p>
</div>
//...code
我在另一个组件中编写了几乎相同的代码并且它可以工作。但是我的代码中有什么问题?
解决方案
推荐阅读
- python - 尝试在不同线程中使用变量时出现 UnboundLocalError
- hp-uft - UFT 无法识别 webfile 对象
- php - mongo find 用户至少订阅了 n 天
- sql - 基于具有非空结果的列值求和
- django - 使用 axios 请求发送 x-csrf-token (Django/Reactjs)
- typo3 - Typo3 9.5 为什么在哪个页面上看不到错误?
- database - 通过 foreach 循环动态返回视图
- python - MinMaxScaler inverse_transform 不同大小的数组
- python - numpy intersect1d 意外关键字参数'return_indices'
- wso2 - 为 WSO2 Developer Studio 调色板设置自定义中介