Vue 项目中使用 Ace 编辑器的问题总结

添加 Ace

此处我们使用 npm 进行安装,在项目路径下,输入 npm install ace-builds,安装完成后,可以看到 acesrc 包。
ace-builds

Ace 配置属性

Ace配置属性文档:https://github.com/ajaxorg/ace/wiki/Configuring-Ace,提供了编辑器支持的属性。
Ace编辑器配置属性

Ace 的使用

首先,根据自己需要,导入相应的文件,

import ace from "ace-builds"
//在 webpack 环境中使用必须要导入
import "ace-builds/webpack-resolver"
// 导入语法模式        
import "ace-builds/src-noconflict/mode-javascript"
// 导入主题
import "ace-builds/src-noconflict/theme-monokai"
// 导入提示
import "ace-builds/src-noconflict/snippets/javascript"
import "ace-builds/src-noconflict/ext-language_tools"

接着,在页面中添加编辑器,

<div class="editorArea">
    <div class="codeEditor" ref="aceEditor">
        console.log(1 + 1);
    </div>
</div>

接着,配置编辑器,

this.aceEditor = ace.edit(this.$refs.aceEditor as string, {
    // 主题
    theme: "ace/theme/monokai",
    // 语言模式
    mode: "ace/mode/javascript",
    // 字号
    fontSize: 14,
    // 激活自动提示
    enableSnippets: true,
    enableLiveAutocompletion: true,
    enableBasicAutocompletion: true,
});

效果如下:
效果
其它配置,未完待续!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 15
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值