• monaco editor


    vite 环境

    {
      "name": "vite-app",
      "private": true,
      "version": "0.0.0",
      "scripts": {
        "dev": "vite",
        "build": "vite build",
        "preview": "vite preview"
      },
      "dependencies": {
        "@vitejs/plugin-react": "^1.3.2",
        "monaco-editor": "^0.33.0",
        "monaco-editor-auto-typings": "^0.4.2",
        "vue": "^3.2.25"
      },
      "devDependencies": {
        "@types/node": "^18.0.3",
        "@vitejs/plugin-vue": "^2.3.3",
        "eval5": "^1.4.7",
        "typescript": "^4.5.4",
        "vite": "^2.9.9",
        "vite-plugin-monaco-editor": "^1.1.0",
        "vue-tsc": "^0.34.7"
      }
    }
    
    
    • vite.config.js
    import { defineConfig } from 'vite'
    import vue from '@vitejs/plugin-vue'
    import monacoEditorPlugin from "vite-plugin-monaco-editor"
    
    export default defineConfig({
      plugins: [
        monacoEditorPlugin({
        }),
        vue(),
      ],
    })
    
    
    • vue
    <script lang="ts">
    import {defineComponent, onMounted, onUnmounted, ref, watchEffect} from "vue";
    import ReactHeader from "./Header";
    import * as monaco from 'monaco-editor';
    import BaseMixins from "./mixins/BaseMixins";
    
    export default defineComponent({
      mixins: [BaseMixins],
      setup() {
        return {
          code: ref(''),
          editor: {},
          LowcodeComponent: ''
        }
      },
      mounted() {
        monaco.languages.typescript.typescriptDefaults.addExtraLib('./func.ts')
        monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
          target: monaco.languages.typescript.ScriptTarget.ES2016,
          allowNonTsExtensions: true,
          module: monaco.languages.typescript.ModuleKind.CommonJS,
          noEmit: true,
          typeRoots: ["node_modules/@types"],
          importHelpers: true,
          strict: false
        });
    
        monaco.languages.typescript.typescriptDefaults.addExtraLib(
            `declare module '/test/test1'{
            export class test1{
                constructor();
                show(): void;
            }
        }
        `
        );
        this.editor = monaco.editor.create(document.getElementById('container'), {
          value: `this.LowcodeComponent = {
      setup() {
        return  {
        }
      },
      methods: {
        add() {
          this.getAction()
        }
      }
    };
    `,
          language: 'javascript',
        });
    
      },
      components: {
        'Header': ReactHeader,
      },
      methods: {
        getCode() {
    
          let code = this.editor.getValue()
          console.log(this.editor)
          eval(code)
          this.LowcodeComponent.methods.add.bind(this)()
        },
      }
    })
    </script>
    
    <template>
      <button @click="getCode">get code</button>
      <div style="height: 1000px">
        <div id="container" style="height: 900px"></div>
      </div>
    </template>
    

    image

  • 相关阅读:
    MVC视图布局页常用代码
    常用meta标签及说明
    重新认识Android
    为什么V8引擎这么快?
    node.js入门及express.js框架
    红星美凯龙CEO车建新的圆融和霸气
    【一个王朝的背影】--余秋雨
    Android源代码结构分析
    Android文件系统的结构
    Mac OSX 平台安装 MongoDB
  • 原文地址:https://www.cnblogs.com/zhuxiang1633/p/16473100.html
Copyright © 2020-2023  润新知