rennzhang / codemirror-editor-vue3

CodeMirror component for Vue3
https://rennzhang.github.io/codemirror-editor-vue3
MIT License
202 stars 41 forks source link

请问能支持java代码编写吗 #34

Closed 1076965238 closed 1 year ago

1076965238 commented 1 year ago

请问能支持java代码编写吗

rennzhang commented 1 year ago

java 需要使用 clike语言包,官网示例: https://codemirror.net/5/mode/clike/index.html

具体代码如下:

<template>
  <div>
    java lang:
    <Codemirror
      v-model:value="code"
      :options="cmOptions"
      border
      :height="600"
      @change="onChange"
    >
    </Codemirror>
  </div>
</template>

<script lang="ts" setup>
import Codemirror from "codemirror-editor-vue3";

// language
import { EditorConfiguration } from "codemirror";
import "codemirror/mode/clike/clike.js";
// theme
const code = ref(`import com.demo.util.MyType;
import com.demo.util.MyInterface;

public enum Enum {
  VAL1, VAL2, VAL3
}

public class Class<T, V> implements MyInterface {
  public static final MyType<T, V> member;

  private class InnerClass {
    public int zero() {
      return 0;
    }
  }

  @Override
  public MyType method() {
    return member;
  }

  public void method2(MyType<T, V> value) {
    method();
    value.method3();
    member = value;
  }
}
`);
const cmOptions: EditorConfiguration = {
  mode: "text/x-java",
};

/** @description  */
const onChange = (...args) => {
  console.log(" args", args);
};
</script>
1076965238 commented 1 year ago

好的,感谢