ace-editor线上代码编辑器
package.json
{
"name": "vue-cli",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "lizhi@camelotchina.com",
"private": true,
"scripts": {
...
},
"dependencies": {
...
},
"devDependencies": {
...
"brace": "^0.11.0",
"emmet": "git+https://github.com/cloud9ide/emmet-core.git",
...
},
"engines": {
...
},
"browserslist": [
...
]
}
component文件夹——>editor.vue文件
<template>
<div style="width: 100%;height: 330px"></div>
</template>
<script>
require(['emmet/emmet'], function (data) {
window.emmet = data.emmet
});
const ace = require('brace');
export default {
name: 'editor',
props: {
value: {
type: String,
required: true
}
},
data () {
return {
editor: null,
contentBackup: ''
}
},
watch: {
value (val) {
if (this.contentBackup !== val) {
this.editor.setValue(val, 1)
}
},
theme: function (newTheme) {
this.editor.setTheme('ace/theme/' + newTheme)
},
lang: function (newLang) {
this.editor.getSession().setMode('ace/mode/' + newLang)
}
},
mounted () {
let vm = this
require('brace/ext/emmet')
require('brace/ext/language_tools')
let editor = vm.editor = ace.edit(this.$el)
this.$emit('init', editor)
let staticWordCompleter = {
getCompletions: function (editor, session, pos, prefix, callback) {
vm.$emit('setCompletions', editor, session, pos, prefix, callback)
}
}
editor.completers = [staticWordCompleter]
editor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true
})
editor.$blockScrolling = Infinity
editor.setFontSize(16)
editor.setOption('enableEmmet', true)
editor.getSession().setMode('ace/mode/mysql')
editor.setTheme('ace/theme/xcode')
editor.setValue(this.value, 1)
editor.on('change', function () {
let content = editor.getValue()
vm.$emit('input', content)
vm.contentBackup = content
})
}
}
</script>
<style scoped>
</style>
view文件夹的 你的页面文件
<editor v-model="formDynamic" @init="editorInit" @setCompletions="setCompletions"></editor>
methods:{
editorInit(){
require('brace/mode/mysql')
require('brace/theme/xcode')
},
setCompletions (editor, session, pos, prefix, callback) {//自动提示方法
callback(null, this.wordList.map(function (word) {
return {
caption: word.vl,
value: word.vl,
meta: word.meta
}
}))
},
}
mounted(){
if(!!configHighlight){//输入提示
for (let i of configHighlight.split('|')) {
this.wordList.push({'vl': i, 'meta': '关键字'})
}
}
}
最新文章
- CSharpGL(15)用GLSL渲染2种类型的文字
- byte[] 转成图片方法
- JSON与XML的区别比较
- 关于IONIC 报错 XX is not a function
- Linux系统的初化始配置(包括配置网络,修改主机名,关闭firewalld与selinux的生效)
- Android的Notification使用注意事项
- Javascript: 从prototype漫谈到继承(2)
- eclipse提示:This tag and its children can be replaced by one <;TextView/>; and a compound drawable
- 智能车学习(五)&mdash;&mdash; dac学习
- Poj 2528 Mayor&#39;s posters 分类: Brush Mode 2014-07-23 09:12 84人阅读 评论(0) 收藏
- 登录超时自动退出,计算时间差-b
- CMakeLists实战解读--YouCompleteMe
- 速度 Github
- web组件工具之获取表单数据:webUtils
- 指针变量的*p,p以及&;p的区别
- 一、JavaSE语言概述
- AVAudioPlayer与MPMusicPlayerController的区别
- ASP.NETCore的Kestrel服务器
- WPF中的ObservableCollection数据绑定
- mongodb 超出内存限制
热门文章
- eclipse安装使用fat打jar包
- YII - 打印 SQL
- 北京大学Cousera学习笔记--2-计算导论与C语言基础-第一讲.计算机的基本原理-图灵机
- cocos2dx在win10系统上的VS2017运行时报错:丢失MSVCR110.dll
- Fiddler抓包【3】_设置断点修改
- archlinux中安装Oracle12c的过程中遇到的问题
- Visual Studio 2019 16.0 正式版下载
- 【JavaScript】常用的数据类型的处理方式
- 【论文速读】XiangBai_CVPR2018_Rotation-Sensitive Regression for Oriented Scene Text Detection
- day24--面向对象基础