vue调用ace富文本编辑器

1.切换语言

<div class="code-type">
    <label class="radio-inline">
       <input type="radio" value="sh" name="codeType" v-model="scriptType">shell
    </label>
    <label class="radio-inline">
    	<input type="radio" value="batchfile" name="codeType" v-model="scriptType">bat
    </label>
    <label class="radio-inline">
    	<input type="radio" value="perl" name="codeType" v-model="scriptType">perl
    </label>
     <label class="radio-inline">
     	<input type="radio" value="python" name="codeType" v-model="scriptType">python
     </label>
     <label class="radio-inline">
     	<input type="radio" value="powershell" name="codeType" v-model="scriptType">powershell
     </label>
 </div>

2.文本编辑器页面元素

<div v-if="editor_show" class="editor_box">
     <pre id="code" class="ace_editor" style="min-height:400px;width:80%"><textarea class="ace_text-input"></textarea></pre>
 </div>

3.vue中使用

data:{
scriptType: 'sh',
},
methods:{
changeType(lang) {
                //初始化对象
                this.editor = ace.edit("code");

                //设置风格和语言(更多风格和语言,请到github上相应目录查看)
                theme = "clouds"
                language = lang
                this.editor.setTheme("ace/theme/monokai");
                this.editor.session.setMode("ace/mode/" + language);

                //字体大小
                this.editor.setFontSize(18);

                //设置只读(true时只读,用于展示代码)
                this.editor.setReadOnly(false);

                //自动换行,设置为off关闭
                this.editor.setOption("wrap", "free")

                //启用提示菜单
                ace.require("ace/ext/language_tools");
                this.editor.setOptions({
                    enableBasicAutocompletion: true,
                    enableSnippets: true,
                    enableLiveAutocompletion: true
                });
            }
            }
            
         
watch: {
            scriptType(val) {
                this.editor_show = true;
                if (this.editor) {
                    this.editor.destroy();
                    this.editor.container.remove();
                }
                $(".editor_box").append('<pre id="code" class="ace_editor" style="min-height:400px;width:80%"><textarea class="ace_text-input"></textarea></pre>');
                this.changeType(val)
            }
            }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值