Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

codemirror-editor-vue3

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codemirror-editor-vue3

CodeMirror component for Vue3

  • 2.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7K
increased by86.45%
Maintainers
1
Weekly downloads
 
Created
Source

GitHub stars GitHub issues GitHub forks GitHub last commit license

Introduction

The plug-in is based on Codemirror and only supports vue3. In addition to the modes supported by codemirror, this plugin also supports custom log modes.

For complete documentation and more cases, please check codemirror-editor-vue3-docs.(Currently only Chinese version, English version is under planning)

Install

npm install codemirror-editor-vue3 -S
yarn add codemirror-editor-vue3
pnpm i codemirror-editor-vue3 codemirror -S

Use in the global

Do not recommend global registration components, which will result in the type of prompt on the template that cannot be properly obtained.

main.js:

import { createApp } from "vue";
import App from "./App.vue";
import { GlobalCmComponent } from "codemirror-editor-vue3";

const app = createApp(App);
app.use(GlobalCmComponent);
app.mount("#app");

custom component name:

app.use(GlobalCmComponent, { componentName: "customName" });

Use in components

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

<script>
import Codemirror from "codemirror-editor-vue3";

// language
import "codemirror/mode/javascript/javascript.js";

// theme
import "codemirror/theme/dracula.css";

import { ref } from "vue";
export default {
  components: { Codemirror },
  setup() {
    const code = ref(`
var i = 0;
for (; i < 9; i++) {
  console.log(i);
  // more statements
}`);

    return {
      code,
      cmOptions: {
        mode: "text/javascript", // Language mode
        theme: "dracula", // Theme
        lineNumbers: true, // Show line number
        smartIndent: true, // Smart indent
        indentUnit: 2, // The smart indent unit is 2 spaces in length
        foldGutter: true, // Code folding
        styleActiveLine: true, // Display the style of the selected row
      },
    };
  },
};
</script>

Get codemirror instance object

View code

use Codemirror Static property

import { CodeMirror } from "codemirror-editor-vue3";
CodeMirror.Pos(0, 5);

or:

import _CodeMirror from "codemirror";
_CodeMirror.Pos(0, 5);

Other instructions

The codemirror basic style has been introduced inside the codemirror-editor-vue3 plugin, and there is no need to repeatedly introduce the following styles when using:

// base style
import "codemirror/lib/codemirror.css";
import "codemirror/mode/css/css.js";

Keywords

FAQs

Package last updated on 23 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc