【发布时间】:2021-04-23 04:09:11
【问题描述】:
在 Laravel 8 / tailwindcss 2 / Alpinejs 2.8 应用程序中,当显示当前图像和 新图像 1) 可以通过预览选择 2) 使用 axios 由 Js 代码保存 请求 3) 在成功上传当前图像时替换为新的预览图像 当当前图像尺寸较大时,我遇到问题,然后新的上传图像看起来已损坏。 我尝试使用 js 代码将大小设置为新上传文件的表单大小上的图像来修复它:
window.axios.post('/admin/settings/app_big_logo/images/upload', mageUploadData).then((response) => {
let img_app_big_logo = document.querySelector("#img_app_big_logo") // show uploaded image @endsection the form
if (img_app_big_logo) {
// set new uploaded image
img_app_big_logo.src = response.data.settingsItemImgProps.image_url + ( '?dt=' + Math.floor(Date.now() / 1000) )
console.log('document.querySelector("#img_preview_app_big_logo").width::')
console.log(document.querySelector("#img_preview_app_big_logo").width)
// I got width/height of new uploaded image - in console I see small values of image
// But after assigning width/height of preview image
img_app_big_logo.width= document.querySelector("#img_preview_app_big_logo").width //+ "px"
img_app_big_logo.height= document.querySelector("#img_preview_app_big_logo").height //+ "px"
// I check and see prior width/height of PRIOR BIG image - so new uploaded image looks broken
console.log('img_app_big_logo.width::')
console.log(img_app_big_logo.width)
console.log('img_app_big_logo.height::')
console.log(img_app_big_logo.height)
...
}
}).catch((error) => {
console.error(error)
});
为什么会出错以及如何修复?
谢谢!
【问题讨论】:
-
注意:您使用了 Java 标记,但询问的是 JavaScript。
标签: javascript alpine.js