const [code, setCode] = useState()
useEffect(() => {
axios.get(BASE_URL + `/admin/training_institution/apply/qrcode/${id}`, {
responseType: "blob",
headers: {
Authorization: `Bearer ${window.localStorage.getItem("token")}`,
},
}).then(res => {
const img = window.URL.createObjectURL(res?.data)
setCode(img)
})
}, [])
<Image width={150} height={150} src={code} />
使用fetch
const [code, setCode] = useState()
const [code, setCode] = useState()
useEffect(() => {
fetch(`${BASE_URL}/admin/training_institution/apply/qrcode/${id}`, {
headers: {
Authorization: `Bearer ${window.localStorage.getItem('token')}`
}
})
.then(response => response.blob())
.then(blob => {
const img = window.URL.createObjectURL(blob)
setCode(img)
})
.catch(error => {
console.error(error)
})
}, [])
<Image width={150} height={150} src={code} />