我无法根据以下代码显示/隐藏图标。如果 然后显示删除图标,但如果权限 == “PLAYER”,则将其隐藏。deleteprivilege == "ADMIN"
然后下面的代码不起作用,
const [deleteIcon, setDeleteIcon] = useState({ show: false});
useEffect(() => {
const fetchData = async () => {
try {
const res = await Axios.get('http://localhost:8000/service/players');
setPlayerList(res.data.players);
setSearchResults(res.data.players);
const privilege = localStorage.getItem('Privilege');
console.log("Privilege logging in Front End:"+privilege);
showDeleteIcon(privilege);
} catch (e) {
console.log(e);
}
}
fetchData();
}, []);
const showDeleteIcon = (privilege) =>{
if(privilege === "ADMIN"){
setDeleteIcon({show:true})
}else{
setDeleteIcon({show:false})
}
}
{ deleteIcon &&(
<span className="deletePlayerIcon">
<img src="images/deleteIcon.png"/>
</span>
)}
MMMHUHU
慕的地6264312
相关分类