Pārlūkot izejas kodu

优化:编辑器点击富文本框,提示语不消失

zq 1 mēnesi atpakaļ
vecāks
revīzija
a1a46caa08
1 mainītis faili ar 23 papildinājumiem un 0 dzēšanām
  1. 23 0
      src/components/RichText.vue

+ 23 - 0
src/components/RichText.vue

@@ -553,6 +553,29 @@ export default {
           //     this.$emit('selectContentSetMemo', null, annotationId);
           //   }
           // });
+
+          editor.on('focus', () => {
+            const body = editor.getBody();
+            if (body && body.hasAttribute('data-mce-placeholder')) {
+              body.removeAttribute('data-mce-placeholder');
+            }
+          });
+          editor.on('blur', () => {
+            const body = editor.getBody();
+            const content = editor.getContent({ format: 'text' }).trim();
+            if (body && !content && this.placeholder) {
+              body.setAttribute('data-mce-placeholder', this.placeholder);
+            }
+          });
+          editor.on('input', () => {
+            const body = editor.getBody();
+            const content = editor.getContent({ format: 'text' }).trim();
+            if (body && content && body.hasAttribute('data-mce-placeholder')) {
+              body.removeAttribute('data-mce-placeholder');
+            } else if (body && !content && !body.hasAttribute('data-mce-placeholder') && this.placeholder) {
+              body.setAttribute('data-mce-placeholder', this.placeholder);
+            }
+          });
         },
         font_formats:
           '楷体=楷体,微软雅黑;' +