Browse Source

富文本添加alt

rkljw 3 days ago
parent
commit
4c77026a76
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/components/edit/myEditor.vue

+ 10 - 0
src/components/edit/myEditor.vue

@@ -50,6 +50,16 @@ export default {
               return;
             }
             success(json.data.imgUrl);
+            // Listen for the NodeChange event to set the alt attribute
+            const editor = tinymce.activeEditor;
+            editor.on('NodeChange', function(e) {
+              const imgElm = e.element;
+              if (imgElm.nodeName === 'IMG' && imgElm.src === json.data.imgUrl) {
+                console.log("Setting alt attribute to:",  json.data.oldName || '全国政务信息一体化应用平台'); // Debugging: Check the alt value
+                editor.dom.setAttrib(imgElm, 'alt',json.data.oldName || '全国政务信息一体化应用平台'); // Use oldName or a default value
+                editor.off('NodeChange'); // Remove the event listener after setting the alt
+              }
+            });
           };
 
           formData = new FormData();