一、效果
二、代码
<!-- --> <template> <div class='content'> <el-select v-model="aceConfig.theme" class="m-2" placeholder="Select" size="large"> <el-option v-for="item in aceConfig.arr" :key="item" :label="item" :value="item" /> </el-select> <el-button @click="initFail">格式化</el-button> <v-ace-editor v-model:value="dataForm.textareashow" @init="initFail" lang="json" :theme="aceConfig.theme" :options="aceConfig.options" :readonly="aceConfig.readOnly" style="height:300px" class="ace-editor" /> </div> </template> <script setup> import { reactive } from 'vue' import { VAceEditor } from 'vue3-ace-editor'; // 加了这个【import "ace-builds/webpack-resolver";】可能会报错 //(若报错 则需要安装node.js的一个包 就是主题) // 命令:npm install --save-dev file-loader import "ace-builds/webpack-resolver"; import 'ace-builds/src-noconflict/mode-json'; import 'ace-builds/src-noconflict/theme-chrome'; import 'ace-builds/src-noconflict/ext-language_tools'; //ace编辑器配置 const aceConfig = reactive({ lang: 'json', //解析json theme: 'chrome', //主题 arr: [ /*所有主题*/ "ambiance", "chaos", "chrome", "clouds", "clouds_midnight", "cobalt", "crimson_editor", "dawn", "dracula", "dreamweaver", "eclipse", "github", "gob", "gruvbox", "idle_fingers", "iplastic", "katzenmilch", "kr_theme", "kuroir", "merbivore", "merbivore_soft", "monokai", "mono_industrial", "pastel_on_dark", "solarized_dark", "solarized_light", "sqlserver", "terminal", "textmate", "tomorrow", "tomorrow_night", "tomorrow_night_blue", "tomorrow_night_bright", "tomorrow_night_eighties", "twilight", "vibrant_ink", "xcode", ], readOnly: false, //是否只读 options: { enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true, tabSize: 2, showPrintMargin: false, fontSize: 13 } }); //form const dataForm = reactive({ textareashow: '{"A":"A1"}' }); //init const initFail = () => { try { dataForm.textareashow = JSON.stringify(JSON.parse(dataForm.textareashow), null, 2) } catch (e) { console.log(`JSON字符串错误:${e.message}`); } }; </script> <style scoped> </style>
标签:builds,ace,json,vue3,import,tomorrow From: https://www.cnblogs.com/danhuai/p/16731613.html