赞
踩
npm i vue3-ace-editor
import {reactive,defineComponent} from 'vue'
import {VAceEditor} from 'vue3-ace-editor';
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';
<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"/>
注意 : JSON.stringify(dataForm.Example,null,2),将json数据格式化,不然显示在一行
<script lang='ts'> import { ref,reactive,defineComponent} from 'vue' import {VAceEditor} from 'vue3-ace-editor'; 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'; export default defineComponent({ components: {VAceEditor}, setup(props, context) { //ace编辑器配置 const aceConfig = reactive({ lang: 'json', //解析json theme: 'chrome', //主题 readOnly: false, //是否只读 options: { enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true, tabSize: 2, showPrintMargin: false, fontSize: 13 } }); //form const dataForm = reactive({ Example: { abc:'123', def:'345', ghi:{ abc:'123', def:'345', }, jkl:[ { abc:'123', def:'345', },{ abc:'123', def:'345', } ] }, textareashow:'' }); //init const initFail = () => { dataForm.textareashow = JSON.stringify(dataForm.Example,null,2) }; // 返回值 return { aceConfig,dataForm, initFail } } }) </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。