Giter VIP home page Giter VIP logo

Comments (5)

Xing-He avatar Xing-He commented on May 29, 2024

I have dug into the "codemirror", and found that it doesn't support SSR.
However, I am still confused with the css compile issue.

from codemirror-editor-vue3.

Xing-He avatar Xing-He commented on May 29, 2024

I am now trying to use the dynamic import import('codemirror-editor-vue3') to solve this problem. but how can i define CodeMirror's language? as i can't get the CodeMirror object !

from codemirror-editor-vue3.

rennzhang avatar rennzhang commented on May 29, 2024

As you said, Codemirror itself does not support SSR, and I have not intended to do this.

As for the dynamic introduction you said, I don't understand it, it is best to provide Demo.

from codemirror-editor-vue3.

Xing-He avatar Xing-He commented on May 29, 2024

As we can see, I couldn't use CodeMirror on SSR. and couldn't import the codemirror with static import as below:

import CodeMirror from 'codemirror';

Instead, dynamic import

import('codemirror').then((CodeMirror)=>{ CodeMirror.doSomething() })

Hope I made it clear.

from codemirror-editor-vue3.

rennzhang avatar rennzhang commented on May 29, 2024

The parent component:

<template>
  <button @click="visible = !visible">show modal</button>
  <codemirrorDemo v-if="visible" />
</template>

<script lang="ts" setup>
import codemirrorDemo from "./codemirrorDemo.vue";
const visible = ref(false);
</script>

Child components(codemirrorDemo.vue):

<template>
  <Codemirror v-model:value="code" :options="cmOptions" border :height="200" />
</template>

<script lang="ts">
import { ref } from "vue";
import "codemirror/mode/javascript/javascript.js";

const res = await import("codemirror-editor-vue3");

export default defineComponent({
  components: {
    Codemirror: res.default,
  },
  setup() {
    const code = ref(`const obj = {
  name: "peter", 
  age: 18
};
`);

    const cmOptions = {
      mode: "javascript", // 语言模式
      lineNumbers: true, // 显示行号
      smartIndent: true, // 智能缩进
      indentUnit: 2, // 智能缩进单位为4个空格长度
      foldGutter: true, // 启用行槽中的代码折叠
      styleActiveLine: true, // 显示选中行的样式
    };

    return {
      code,
      cmOptions,
    };
  },
});
</script>

from codemirror-editor-vue3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.