diff --git a/src/components/AceEditor/src/AceEditor.tsx b/src/components/AceEditor/src/AceEditor.tsx
index 9323687..d45f478 100644
--- a/src/components/AceEditor/src/AceEditor.tsx
+++ b/src/components/AceEditor/src/AceEditor.tsx
@@ -18,6 +18,7 @@ import type { AceEditorState, AceEditorMethods, AceEditorProps } from './types';
import { deepMerge } from '/@/utils';
import { useAppStore } from '/@/store/modules/app';
import './ace-config';
+import { isFunction } from '/@/utils/is';
export default defineComponent({
name: 'AceEditor',
@@ -35,7 +36,7 @@ export default defineComponent({
_isSettingContent: false,
});
- const getProps = computed((): Recordable => {
+ const getProps = computed((): AceEditorProps => {
return {
...props,
...(unref(propsRef) as any),
@@ -66,6 +67,10 @@ export default defineComponent({
const content = editor.getValue();
state._contentBackup = content;
emit('update:value', content);
+ emit('change', content);
+ // 解决通过useAceEditor注册onChange时不起作用的问题
+ const { onChange } = unref(getProps);
+ onChange && isFunction(onChange) && onChange.call(undefined, content);
});
// Event Binding
editor.on('blur', (e: Event) => emit('blur', e));
diff --git a/src/components/AceEditor/src/emits.ts b/src/components/AceEditor/src/emits.ts
index 1702f3c..b9314f9 100644
--- a/src/components/AceEditor/src/emits.ts
+++ b/src/components/AceEditor/src/emits.ts
@@ -1,9 +1,9 @@
export const basicEmits = [
'register',
'update:value',
+ 'change',
'blur',
'input',
- 'change',
'changeSelectionStyle',
'changeSession',
'copy',
diff --git a/src/components/AceEditor/src/types.ts b/src/components/AceEditor/src/types.ts
index f7f8d2e..64ed741 100644
--- a/src/components/AceEditor/src/types.ts
+++ b/src/components/AceEditor/src/types.ts
@@ -22,6 +22,12 @@ export interface AceEditorProps {
printMargin: boolean | number;
minLines: number;
maxLines: number;
+
+ /**
+ * Callback executed when editor content
+ * @param content
+ */
+ onChange?: (content: string) => void;
}
export interface AceEditorMethods {
diff --git a/src/locales/lang/en/routes/demo.ts b/src/locales/lang/en/routes/demo.ts
index b66e786..2065997 100644
--- a/src/locales/lang/en/routes/demo.ts
+++ b/src/locales/lang/en/routes/demo.ts
@@ -54,7 +54,7 @@ export default {
aceEditor: 'Ace editor',
aceEditorBasic: 'Ace Basic',
useAceEditor: 'Use AceEditor',
- useAceEditorReactive: 'Use AceEditor Reactive',
+ useAceEditorAdvanced: 'Use AceEditor Advanced',
tinymce: 'Rich text',
tinymceBasic: 'Basic',
diff --git a/src/locales/lang/zh-CN/routes/demo.ts b/src/locales/lang/zh-CN/routes/demo.ts
index 429ba57..26b98a6 100644
--- a/src/locales/lang/zh-CN/routes/demo.ts
+++ b/src/locales/lang/zh-CN/routes/demo.ts
@@ -53,7 +53,7 @@ export default {
aceEditor: 'Ace编辑器',
aceEditorBasic: 'ACE基础使用',
useAceEditor: 'UseAceEditor',
- useAceEditorReactive: 'UseAceEditor响应',
+ useAceEditorAdvanced: 'ACE高级使用',
tinymce: '富文本',
tinymceBasic: '基础使用',
diff --git a/src/router/routes/demo/comp.ts b/src/router/routes/demo/comp.ts
index 9aa36bb..f68896f 100644
--- a/src/router/routes/demo/comp.ts
+++ b/src/router/routes/demo/comp.ts
@@ -361,11 +361,11 @@ const comp: AppRouteModule = {
},
},
{
- path: 'useAceEditorReactive',
- name: 'useAceEditorReactiveDemo',
- component: () => import('/@/views/demo/editor/ace/useAceEditorReactive.vue'),
+ path: 'useAceEditorAdvanced',
+ name: 'useAceEditorAdvancedDemo',
+ component: () => import('/@/views/demo/editor/ace/useAceEditorAdvanced.vue'),
meta: {
- title: t('routes.demo.editor.useAceEditorReactive'),
+ title: t('routes.demo.editor.useAceEditorAdvanced'),
},
},
],
diff --git a/src/views/demo/editor/ace/index.vue b/src/views/demo/editor/ace/index.vue
index 32aa921..a5f1b5a 100644
--- a/src/views/demo/editor/ace/index.vue
+++ b/src/views/demo/editor/ace/index.vue
@@ -6,23 +6,30 @@
>
-
+ 语言
{{ lang }}
-
+ 主题
{{ theme }}
+
diff --git a/src/views/demo/editor/ace/useAceEditorReactive.vue b/src/views/demo/editor/ace/useAceEditorReactive.vue
deleted file mode 100644
index d3dbeed..0000000
--- a/src/views/demo/editor/ace/useAceEditorReactive.vue
+++ /dev/null
@@ -1,82 +0,0 @@
-
-
-
-
-
- {{ lang }}
-
-
- {{ theme }}
-
-
-
-
-
-
-
-
-