欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > 前端编辑器JSON HTML等,vue2-ace-editor,vue3-ace-editor

前端编辑器JSON HTML等,vue2-ace-editor,vue3-ace-editor

2025/2/22 16:46:39 来源:https://blog.csdn.net/qq_42975676/article/details/144427839  浏览:    关键词:前端编辑器JSON HTML等,vue2-ace-editor,vue3-ace-editor

与框架无关
vue2-ace-editor有问题,ace拿不到(brace)
一些组件都是基于ace-builds或者brace包装的
不如直接用下面的,不如直接使用下面的
在这里插入图片描述

<template><div ref="editor" class="json-editor"></div>
</template><script>
import ace from 'ace-builds';
import 'ace-builds/webpack-resolver'; // 确保 Webpack 正确解析模块
import 'ace-builds/src-noconflict/mode-json'; // 引入 JSON 模式
import 'ace-builds/src-noconflict/theme-monokai'; // 引入 Monokai 主题export default {name: 'JsonEditor',props: {value: {type: String,default: '',},},data() {return {editor: null,};},watch: {value(newValue) {if (newValue !== this.editor.getValue()) {this.editor.setValue(newValue, 1); // 1 表示不触发 change 事件}},},mounted() {this.initEditor();},beforeDestroy() {if (this.editor) {this.editor.destroy();this.editor = null;}},methods: {initEditor() {this.editor = ace.edit(this.$refs.editor, {mode: 'ace/mode/json',theme: 'ace/theme/monokai',tabSize: 2,useWorker: false, // 禁用 worker 以避免 JSON 解析错误时的警告minLines: 10,maxLines: 30,fontSize: '14px',showPrintMargin: false,});this.editor.setValue(this.value, 1); // 初始化值this.editor.getSession().on('change', () => {this.$emit('input', this.editor.getValue());});},},
};
</script><style scoped>
.json-editor {width: 100%;height: 400px;
}
</style>

解决光标错位

.ace_editor,
.ace_editor * {font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Droid Sans Mono', 'Consolas', monospace !important;font-size: 12px !important;font-weight: 400 !important;letter-spacing: 0 !important;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词