我在反应项目中有羽毛笔编辑器,并且图像处理程序用于上传图像,但我必须在羽毛笔编辑器中为所有图像元素添加类。这是我的图像处理程序代码
imageHandler() {
let self=this
const Cryptr = require('cryptr');
const cryptr = new Cryptr(key);
const users = localStorage.getItem('users') ? JSON.parse(cryptr.decrypt(localStorage.getItem('users'))) : {}
let loggedinUser = users[users.lastLoginId];
const input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.click();
input.onchange = async () => {
const file = input.files[0];
const formData = new FormData();
// const formData = new FormData();
formData.append('image', file);
const config = {
headers: {
'content-type': 'multipart/form-data',
'x-access-handler': loggedinUser.token
}
};
const res = new Promise(function(resolve, reject) {
axios.post(API_URL + 'api/v1/postblogimage', formData, config)
.then((response) => {
if (response.data.error == 'false' || response.data.error == false) {
if (response.data.status == 200 && response.data.message == "Image uploaded successfully") {
const range = self.quill.getSelection(true);
// Insert temporary loading placeholder image
// this.quill.insertEmbed(range.index, 'image', `${window.location.origin}/images/loaders/placeholder.gif`);
// Move cursor to right side of image (easier to continue typing)
self.quill.setSelection(range.index + 1);
// Remove placeholder image
self.quill.deleteText(range.index, 1);
// Insert uploaded image
self.quill.insertEmbed(range.index, 'image', response.data.data[0].imageURL);
}
}
// }
}).catch((error) => {
// reject(Error("It broke"));
});
});
};
}
有人可以帮我解决这个问题,因为我已经尝试了很长时间并且没有成功。任何帮助或建议将不胜感激。