Like vue2-ace-editor but more functional and supports Vue 3
npm install vue3-ace-editorvue3-ace-editor
====================

A packaging of ace. Inspired by vue2-ace-editor, but supports Vue 3
1. Install
``shell`
yarn add vue3-ace-editor
2. Register it in components of Vue options
`js
import { VAceEditor } from 'vue3-ace-editor';
export default {
data,
methods,
...
components: {
VAceEditor,
},
}
`
3. Use the component in template
`html`
@init="editorInit"
lang="html"
theme="chrome"
style="height: 300px" />
prop v-model:value is required. has no height by default. Its height must be specified manually, or set both min-lines and max-lines to make the editor's height auto-grow.
prop lang, theme is same as ace-editor's doc
1. This component uses ace-builds directly, instead of the outdated wrapper brace
1. DOM size changes are detected automatically using ResizeObserver, thus no width / height props needed.readonly
1. For easier usage, more props / events added / emitted.
1. Prop : This Boolean attribute indicates that the user cannot modify the value of the control.placeholder
1. Prop : A hint to the user of what can be entered in the control.wrap
1. Prop : Indicates whether the control wraps text.printMargin
1. Prop : A short hand of showPrintMargin and printMarginColumn.minLines
1. Prop and maxLines: Specifiy the minimum and maximum number of lines.focus
1. All ace events emitted. Docs can be found here:
1. Some commonly used methods , blur, selectAll provided as shortcuts.
To enable syntax checking, module ace/mode/lang_worker must be registered, and option useWorker: true must be set.
Take JSON for example:
`ts
import workerJsonUrl from 'ace-builds/src-noconflict/worker-json?url'; // For vite
import workerJsonUrl from 'file-loader?esModule=false!ace-builds/src-noconflict/worker-json.js'; // For webpack / vue-cli
ace.config.setModuleUrl('ace/mode/json_worker', workerJsonUrl);
`
`html`
See also https://github.com/CarterLi/vue3-ace-editor/issues/3#issuecomment-768190528 to load the worker file from CDN
Using of ace-builds/webpack-resolver is removed due to bug https://github.com/CarterLi/vue3-ace-editor/issues/3. You MUST import theme and mode yourself. eg.
`js`
import 'ace-builds/src-noconflict/mode-json';
import 'ace-builds/src-noconflict/theme-chrome';
To use dynamic loading to avoid first-load overhead
`js
import ace from 'ace-builds';
import modeJsonUrl from 'ace-builds/src-noconflict/mode-json?url';
ace.config.setModuleUrl('ace/mode/json', modeJsonUrl);
import themeChromeUrl from 'ace-builds/src-noconflict/theme-chrome?url';
ace.config.setModuleUrl('ace/theme/chrome', themeChromeUrl);
`
Find all supported themes and modes in node_modules/ace-builds/src-noconflict`
* Preview:
* Source:
MIT