Vue 中引用 ace-editor

本文详细介绍了如何在Vue项目中集成Ace Editor代码编辑器,包括从源码下载、本地运行、文件复制到项目中,再到在index.html中引入JS文件及在组件中进行配置的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.先在官网下载源码https://github.com/ajaxorg/ace,在本地运行一下命令

npm install
node ./Makefile.dryice.js

2.copy build文件夹到项目中

3.在vue的index.html里引用js

<script src="static/js/ace-editor/src/ace.js"></script>
<script src="static/js/ace-editor/src/ext-language_tools.js"></script>

4.在需要用ace-editor的控件里的mounted方法添加一下配置即可

mounted () {
  // eslint-disable-next-line
  editor = ace.edit('editor')
  editor.session.setMode('ace/mode/javascript') // 设置语言
  editor.setTheme('ace/theme/tomorrow')// 设置主题
  // enable autocompletion and snippets
  editor.setOptions({
    enableBasicAutocompletion: true,
    enableSnippets: true,
    enableLiveAutocompletion: true// 设置自动提示
  })
  // this.inputValue = editor.getValue() // 读值
  // editor.setValue(editorValue)
  /* eslint-enable no-alert, no-console */
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值