上传成功时同步更新 item.value,删除图片时同步更新 item.value,就可以了
上传成功时同步更新 item.value,删除图片时同步更新 item.value,就可以了
// 删除时的钩子
// const beforeRemove = (file: any, fileList: any, key: any) => {
// var index = 0;
// formData[key].map((value: any, inx: any) => {
// if (value.uid === file.uid) index = inx;
// });
// formData[key].splice(index, 1);
// };
const beforeRemove = (file: any, fileList: any, key: any) => {
// 删除formData里的图片
const arr = formData.value[key] || [];
const index = arr.findIndex((v: any) => v.uid === file.uid);
if (index > -1) {
arr.splice(index, 1);}
// 新增:同步更新formList对应item.value
const targetItem = formList.value.find(item => item.key === key);
if (targetItem) {
targetItem.value = [...arr];}
};
// 上传成功
// const handleUploadSuccess = (response: any, file: any, fileList: any, imgKey: any) => {
// const that = this;
// const { code, msg } = response;
// if (code === 2000) {
// const { url } = response.data;
// const { name } = file;
// const type = isImage(name);
// if (!type) {
// errorMessage('只允许上传图片');
// } else {
// const uploadImgKey = formData[imgKey];
// if (!uploadImgKey || uploadImgKey === '') {
// formData[imgKey] = [];
// }
// // console.log(len)
// const dict = {
// name: name,
// url: getBaseURL() + url,
// };
// formData[imgKey].push(dict);
//
// // 新增:同步更新 formList 对应 item 的 value
// const targetItem = formList.value.find(item => item.key === imgKey);
// if (targetItem) {
// targetItem.value = [...formData.value[imgKey]];
// }
// }
// } else {
// errorMessage('上传失败,' + JSON.stringify(msg));
// }
// };
const handleUploadSuccess = (response: any, file: any, fileList: any, imgKey: any) => {
const { code, msg } = response;
if (code === 2000) {
const { url } = response.data;
const { name } = file;
const type = isImage(name);
if (!type) {
errorMessage('只允许上传图片');
return;
}
// 初始化数组
if (!formData.value[imgKey]) {
formData.value[imgKey] = [];
}
const dict = {
name: name,
url: getBaseURL() + url,
};
formData.value[imgKey].push(dict);
// 新增:同步更新 formList 对应 item 的 value
const targetItem = formList.value.find(item => item.key === imgKey);
if (targetItem) {
targetItem.value = [...formData.value[imgKey]];
}} else {
errorMessage('上传失败,' + JSON.stringify(msg));}
};
修正E:workdjango-vue3-adminwebsrcviewssystemconfigcomponentsformContent.vue中的js{{formContent.vue(uploading...)}}
问 django-vue3-admin前端系统配置背景图