{"id":15647344,"url":"https://github.com/egoist/vue-cm","last_synced_at":"2025-04-30T11:43:28.007Z","repository":{"id":45275144,"uuid":"99130038","full_name":"egoist/vue-cm","owner":"egoist","description":"CodeMirror component for Vue.js","archived":false,"fork":false,"pushed_at":"2021-12-25T14:23:49.000Z","size":81,"stargazers_count":45,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T01:32:24.209Z","etag":null,"topics":["codemirror","component","vue"],"latest_commit_sha":null,"homepage":"https://vue-cm.netlify.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/egoist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-02T15:04:53.000Z","updated_at":"2024-05-20T11:10:00.000Z","dependencies_parsed_at":"2022-09-02T17:09:09.082Z","dependency_job_id":null,"html_url":"https://github.com/egoist/vue-cm","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fvue-cm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fvue-cm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fvue-cm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fvue-cm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/vue-cm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251692899,"owners_count":21628585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codemirror","component","vue"],"created_at":"2024-10-03T12:18:43.449Z","updated_at":"2025-04-30T11:43:27.941Z","avatar_url":"https://github.com/egoist.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# vue-cm\n\n[![NPM version](https://img.shields.io/npm/v/vue-cm.svg?style=flat)](https://npmjs.com/package/vue-cm) [![NPM downloads](https://img.shields.io/npm/dm/vue-cm.svg?style=flat)](https://npmjs.com/package/vue-cm) [![CircleCI](https://circleci.com/gh/egoist/vue-cm/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/vue-cm/tree/master)  [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/egoist/donate)\n\n*[CodeMirror](https://codemirror.net/) is a versatile text editor implemented in JavaScript for the browser.*\n\n**NOTE:** I'm aware of the existence of [vue-codemirror](https://github.com/surmon-china/vue-codemirror), but I built this one for good reasons:\n\n- Smaller.\n- No unnecessary abstractions, which means simpler API.\n- Prebuilt bundle, you can use it with or without a bundler.\n- More modern-ish.\n- Simply better.\n\n## Install\n\n```bash\nyarn add codemirror vue-cm\n```\n\nCDN: [UNPKG](https://unpkg.com/vue-cm/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/vue-cm/dist/)\n\n\u003e **NOTE**: You need to include CodeMirror as well if you're using the CDN version, basically we access it via `window.CodeMirror` in the CDN version.\n\n## Usage\n\n```vue\n\u003ctemplate\u003e\n  \u003ccode-mirror \n    v-model=\"code\"\n    :options=\"options\"\u003e\n  \u003c/code-mirror\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nimport CodeMirror from 'vue-cm'\n\n// Using language mode\nimport 'codemirror/mode/javascript/javascript'\n\nexport default {\n  component: {\n    CodeMirror\n  },\n\n  data() {\n    return { \n      code: '',\n      options: {\n        mode: 'javascript'\n      }\n    }\n  }\n}\n\u003c/script\u003e\n\n\u003cstyle src=\"codemirror/lib/codemirror.css\"\u003e\u003c/style\u003e\n```\n\n`v-model` for components is just a syntax sugar of:\n\n```diff\n\u003ccode-mirror \n-  v-model=\"code\"\n+  :value=\"code\"\n+  @change=\"newValue =\u003e { code = newValue }\"\n  :options=\"options\"\u003e\n\u003c/code-mirror\u003e\n```\n\n### Props\n\n- `value`: `string` Editor value\n- `options`: `object` CodeMirror instance options\n- `preserveScrollPosition` `default: false`: Preserve previous scroll position after updating value.\n\n### Events\n\n- `change`: Emitted when a change is made, args:\n  - `newValue`: New editor value\n- `focus`: Emitted when the editor is focused\n- `blur`: Emitted when the editor loses focus\n- `scroll`: Emitted when the editor is scrolled, args:\n  - `scrollInfo`\n- `cursorActivity`: Emitted when cursor is moved, args:\n  - `codemirror`: CodeMirror instance\n\n### Methods\n\n- `focus()`: focuses the CodeMirror instance\n- `getCodeMirror()`: get the CodeMirror instance\n\nYou can interact with the `CodeMirror` component by using a `ref` attribute, eg: `\u003ccode-mirror ref=\"editor\"\u003e\u003c/code-mirror\u003e`, then you can call `this.$refs.editor.getCodeMirror()` in parent component's `mounted` hook to get the CodeMirror instance we use in the child component.\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n\n## Author\n\n**vue-cm** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.\u003cbr\u003e\nAuthored and maintained by egoist with help from contributors ([list](https://github.com/egoist/vue-cm/contributors)).\n\n\u003e [egoist.moe](https://egoist.moe) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fvue-cm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Fvue-cm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fvue-cm/lists"}