I have a form, where I need to show the status below the form. When I submit the form, depending on axios post success and failure I show the status. As of today I am able to show the error status as below
我想要什么,当提交是成功的,我想显示如下状态.
我有以下代码.
//State
const [stats, setStatus] = useState(null);
//axios post
try {
const res = await axios.post('/exec/addcontroller',
{user, name, ipaddr, port, sshuser, sshpass, sshport, license},
{headers: {
'Content-Type': 'application/json',
'Authorization': token,
}}
).then( function (res) {
if(res.status === 200) {
//success
} else {
setStatus("Error");
}
});
}catch(err) {
setStatus(err.response.data.message);
}
//form code goes here
//status div
{status && <div id="error">{status}</div>}
而css看起来如下所示
#error {
color: #FF0040;
border: 1px solid #F7819F;
padding: 5px;
background-color: #F8E0E6;
}
所以我在成功 case 中需要的是,我想在深绿色字母中显示状态,并将背景显示为浅绿色.怎么做到那样的react 方式呢?