vue2 安装 vue-codemirror
时间: 2023-12-07 15:39:09 浏览: 113
vue使用codemirror的两种用法
5星 · 资源好评率100%
你可以通过以下步骤在Vue2中安装vue-codemirror:
1.使用npm或yarn安装vue-codemirror和codemirror:
```shell
npm install vue-codemirror codemirror@5.46.0 --save
```
2.在Vue组件中导入vue-codemirror:
```javascript
import VueCodemirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
import 'codemirror/theme/base16-dark.css'
import 'codemirror/mode/javascript/javascript.js'
export default {
components: {
VueCodemirror
}
}
```
3.在Vue组件中使用vue-codemirror:
```html
<template>
<div>
<vue-codemirror v-model="code" :options="options"></vue-codemirror>
</div>
</template>
<script>
export default {
data() {
return {
code: '',
options: {
tabSize: 4,
mode: 'javascript',
theme: 'base16-dark',
lineNumbers: true,
line: true,
readOnly: false,
autofocus: true
}
}
}
}
</script>
```
阅读全文