vue3-ace-editor如何配置语法
作者:兜小糖的小秃毛
这篇文章主要介绍了vue3-ace-editor如何配置语法问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
vue3-ace-editor配置语法
<template> <v-ace-editor v-model:value="sqlContent" @init="editorInit" lang="javascript" :options="{ enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true, fontSize: 14, tabSize: 2, showPrintMargin: false, highlightActiveLine: true, }" theme="monokai" style="height: 400px; width: 400px; background: #000; color: #fff" > </v-ace-editor> </template>
<script> import { defineComponent, reactive, toRefs, ref, onMounted, nextTick, } from "vue"; import * as ace from 'ace-builds'; ace.config.set('basePath', '/static/src-min-noconflict/'); import { VAceEditor } from "vue3-ace-editor"; export default defineComponent({ name: "page-three", components: { VAceEditor, }, setup() { const sqlContent = ref(""); const state = reactive({ test: "", }); function editorInit() { require("ace-builds/src-noconflict/ext-language_tools"); require("ace-builds/src-noconflict/snippets/sql"); require("ace-builds/src-noconflict/mode-sql"); require("ace-builds/src-noconflict/theme-monokai"); require("ace-builds/src-noconflict/mode-html"); require("ace-builds/src-noconflict/mode-html_elixir"); require("ace-builds/src-noconflict/mode-html_ruby"); require("ace-builds/src-noconflict/mode-javascript"); require("ace-builds/src-noconflict/mode-python"); require("ace-builds/src-noconflict/snippets/less"); require("ace-builds/src-noconflict/theme-chrome"); require("ace-builds/src-noconflict/ext-static_highlight"); require("ace-builds/src-noconflict/ext-beautify"); } onMounted(() => { nextTick(() => { editorInit; }); }); return { sqlContent, ...toRefs(state), editorInit, }; }, }); </script>
<style> /* 修改光标颜色 */ .ace_cursor { color: #fff !important; } </style>
vue3-ace-editor报Failed to execute ‘importScripts‘ on ‘WorkerGlobalScope‘错误处理
因为项目需要引入vue3-ace-editor编辑器,下面是引入后的设置
引入后发现每个只要用到ace-editor的组件就报
Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://172.16.38.100:3000/worker-javascript.js' failed to load.
如下:
本以为应该百度都有解决方案,所以也不在意,结果发现百度出来的试过都不对,先叫相关同事解决说可能是引入js的方式有问题,他没空后我试了一下 也不是。so,我翻墙去了。
得到了正确的答案,为了不翻墙就能找到答案,特意写篇博客
我在项目里面就是这样的
看了一下文档,这个设置为ture主要是用于检查语法,具体看下图:
ok,按上面的操作就不报错啦。搞定,nice!
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。