![](/img/trans.png)
[英]How to render an Image in react which is coming from Nodejs backend as res.json()?
[英]React doesn't render/load dynamic image URL's coming from sanity backend
我正在學習理智地做出反應,我正在使用谷歌新的 React OAuth 方法。 我能夠使用 google 登錄提示登錄,返回用戶 object,其中包含用戶唯一 ID、個人資料圖像 URL 和其他詳細信息。 但是由於某種原因,反應沒有渲染成功登錄后來自理智后端的圖像。
編輯:如果我手動將圖像 URL 設置為 src,則圖像會呈現。
虛擬用戶集:
const users={
_id:"128379126391jk21",
_type:"users",
name:"user name",
image:"https:xyz.com",
.
.
.
}
首頁.JSX:
const [user, setUser] = useState(null);
useEffect(() => {
console.log("userId " + userId); // 128379126391jk21
const query = userQuery(userId); // query to search the user.
client.fetch(query).then((data) => {// fetches the user from the server
setUser(data[0]); // sets user object
});
}, []);
<Link to={`user-profile/${user?._id}`}>
<img src={user?.image} width ={"200px"} height={"150px"} alt="logo"/>
</Link>
通過mdn文檔搜索后,我遇到了一個叫做 referrerPolicy 的東西,noreferrer 解決了我的圖像加載問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.