{{ title }} [读/写]
当前位置:   article > 正文

vue使用代码编辑器vue2-ace-editor_vue2 ace editor 开发文档

vue2 ace editor 开发文档

一、安装

npm install --save-dev vue2-ace-editor
  • 1

二、子组件

<template>
  <div class="echart-pie-wrap">
    <div class="myEditorTop">{{ title }} [/]</div>
    <editor
      ref="myEditor"
      @init="editorInit"
      :value="value"
      :lang="language"
      theme="monokai"
      :options="options"
    ></editor>
  </div>
</template>

<script>
import Editor from "vue2-ace-editor";
// 主题
import "brace/theme/monokai";
// 代码片段
import "brace/snippets/javascript";
import "brace/snippets/dockerfile";
import "brace/snippets/python";
import "brace/snippets/php";
import "brace/snippets/html";
import "brace/snippets/css";
import "brace/snippets/ruby";
// 代码语言
import "brace/mode/javascript";
import "brace/mode/dockerfile";
import "brace/mode/python";
import "brace/mode/php";
import "brace/mode/html";
import "brace/mode/ruby";
import "brace/mode/css";
// 语言扩展
import "brace/ext/language_tools";
import "brace/ext/emmet";
import "brace/ext/beautify";
import "brace/ext/searchbox";
import "brace/ext/chromevox";
import "brace/ext/error_marker";
import "brace/ext/keybinding_menu";
import "brace/ext/linking";
import "brace/ext/modelist";
import "brace/ext/old_ie";
import "brace/ext/settings_menu";
import "brace/ext/spellcheck";
import "brace/ext/split";
import "brace/ext/static_highlight";
import "brace/ext/statusbar";
import "brace/ext/whitespace";
import "brace/ext/textarea";
import "brace/ext/themelist";
export default {
  components: {
    Editor
  },

  props: {
    title: { type: String, default: "编辑器" },
    value: {
      type: String,
      default: ""
    },
    language: { type: String, default: "html" }
  },

  model: {
    prop: "value",
    event: "change"
  },
  data() {
    return {
      options: {
        enableBasicAutocompletion: true, // 启用基本自动完成
        enableSnippets: true, // 启用代码段
        enableLiveAutocompletion: true, // 启用实时自动完成
        printMarginColumn: 30,
        displayIndentGuides: false, // 显示参考线
        enableEmmet: true, // 启用Emmet
        tabSize: 6, // 标签大小
        fontSize: 14, // 设置字号
        useWorker: true, // 使用辅助对象
        showPrintMargin: false, //去除编辑器里的竖线
        enableMultiselect: true, //     选中多处
        readOnly: false, // 是否只读
        showFoldWidgets: true, // 显示折叠部件
        fadeFoldWidgets: true, // 淡入折叠部件
        wrap: true //换行
      }
    };
  },
  methods: {
    editorInit: function (editor) {
      console.log("debug log --> ", editor);
      // 窗口自适应
      // editor.resize();
      // 监听编辑器变化
      editor.getSession().on("change", val => {
        console.log("debug log --> ", editor.getValue());

        this.$emit("change", editor.getValue());
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.echart-pie-wrap {
  width: 100%;
  height: 500px;
  .myEditorTop {
    height: 45px;
    display: flex;
    align-items: center;
    background-color: #333;
    padding-left: 50px;
    color: rgb(241, 238, 8);
    font-weight: bold;
  }
}
</style>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124

三、父组件

<template>
  <div>
    <MyEditor v-model="code" language="dockerfile" title="dockerfile">
    </MyEditor>
  </div>
</template>

<script>
import MyEditor from "./myEditor";
export default {
  components: {
    MyEditor
  },
  data() {
    return {
      code: ""
    };
  },
  methods: {}
};
</script>

<style lang="scss" scoped></style>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签