monaco.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div ref="code_box" class="text">
  3. <Input v-model="content" type="textarea" placeholder="" @on-change="changeContent" />
  4. </div>
  5. </template>
  6. <script>
  7. // import * as monaco from 'monaco-editor';
  8. // import 'monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution';
  9. export default {
  10. data() {
  11. return {
  12. monacoInstance: null,
  13. content: '',
  14. };
  15. },
  16. props: {
  17. value: {
  18. type: String,
  19. default: '',
  20. },
  21. },
  22. watch: {
  23. value(nal) {},
  24. },
  25. mounted() {
  26. // this.seteditor();
  27. this.content = this.value;
  28. },
  29. methods: {
  30. changeContent() {
  31. this.$emit('change', this.content);
  32. },
  33. setValue(val) {
  34. // this.monacoInstance.setValue(val)
  35. },
  36. seteditor() {
  37. // 初始化编辑器实例
  38. this.monacoInstance = monaco.editor.create(this.$refs.code_box, {
  39. value: this.value,
  40. theme: 'vs', // vs, hc-black, or vs-dark
  41. language: 'html', // shell、sql、python
  42. readOnly: false, // 不能编辑
  43. });
  44. // 编辑器内容发生改变时触发
  45. this.monacoInstance.onDidChangeModelContent(() => {
  46. this.$emit('change', this.monacoInstance.getValue());
  47. });
  48. },
  49. },
  50. beforeDestroy() {
  51. this.monacoInstance.dispose();
  52. this.monacoInstance = null;
  53. },
  54. };
  55. </script>
  56. <style lang="css" scoped>
  57. .editor {
  58. width: 100%;
  59. margin: 0 auto;
  60. }
  61. .text /deep/ .ivu-input-wrapper {
  62. min-height: 600px;
  63. }
  64. .text /deep/ textarea.ivu-input {
  65. min-height: 600px;
  66. }
  67. .text {
  68. border: 1px solid #ccc;
  69. min-height: 600px;
  70. }
  71. .w-e-text-container {
  72. /* height: 490px !important; */
  73. }
  74. </style>