Skip to content

Commit 3d1252d

Browse files
committed
[vue3] 兼容老版本
1 parent cef5acd commit 3d1252d

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,16 @@ The code type message can display code and multi-line text more friendly, the ty
486486
First you need to configure **Highlight.js**, install it at the main.js entry, see [https://www.npmjs.com/package/highlight.js](https://www.npmjs.com/package/highlight.js)
487487

488488
```js
489-
import Terminal from 'vue-web-terminal'
489+
import {Terminal, configHighlight} from 'vue-web-terminal'
490490
import hljs from 'highlight.js'
491491
import java from 'highlight.js/lib/languages/java'
492492
import vuePlugin from "@highlightjs/vue-plugin"
493493
import 'highlight.js/styles/tomorrow-night-bright.css'
494494

495495
hljs.registerLanguage('java', java)
496496
Vue.use(vuePlugin)
497-
Vue.use(Terminal, {highlight: true})
497+
Vue.use(Terminal)
498+
configHighlight(true)
498499
```
499500

500501
vue2 version dependency recommendation, vue3 just use the latest version.
@@ -513,22 +514,22 @@ vue2 version dependency recommendation, vue3 just use the latest version.
513514
It also only needs to be installed at the main.js entry. Recommended version: `"vue-codemirror": "^4.0.6"`
514515

515516
```js
517+
import {Terminal, configCodemirror} from 'vue-web-terminal'
516518
import VueCodemirror from 'vue-codemirror'
517519
import 'codemirror/lib/codemirror.css'
518520
import 'codemirror/theme/darcula.css'
519521
import 'codemirror/mode/clike/clike.js'
520522
import 'codemirror/addon/edit/closebrackets.js'
521523

522524
Vue.use(VueCodemirror)
523-
Vue.use(Terminal, {
524-
codemirror: {
525-
tabSize: 4,
526-
mode: 'text/x-java',
527-
theme: "darcula",
528-
lineNumbers: true,
529-
line: true,
530-
smartIndent: true
531-
}
525+
Vue.use(Terminal)
526+
configCodemirror({
527+
tabSize: 4,
528+
mode: 'text/x-java',
529+
theme: "darcula",
530+
lineNumbers: true,
531+
line: true,
532+
smartIndent: true
532533
})
533534
```
534535

README_ZH.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,16 @@ code类型消息支持 `highlight.js` 高亮显示。
486486
,在main.js入口安装,详细配置见[https://www.npmjs.com/package/highlight.js](https://www.npmjs.com/package/highlight.js)
487487

488488
```js
489-
import Terminal from 'vue-web-terminal'
489+
import {Terminal, configHighlight} from 'vue-web-terminal'
490490
import hljs from 'highlight.js'
491491
import java from 'highlight.js/lib/languages/java'
492492
import vuePlugin from "@highlightjs/vue-plugin"
493493
import 'highlight.js/styles/tomorrow-night-bright.css'
494494

495495
hljs.registerLanguage('java', java)
496496
Vue.use(vuePlugin)
497-
Vue.use(Terminal, {highlight: true})
497+
Vue.use(Terminal)
498+
configHighlight(true)
498499
```
499500

500501
vue2版本依赖推荐,vue3使用最新的版本即可
@@ -514,22 +515,22 @@ code类型消息也支持 `codemirror`
514515
同样只需要在main.js入口安装即可,vue2版本推荐:`"vue-codemirror": "^4.0.6"`
515516

516517
```js
518+
import {Terminal, configCodemirror} from 'vue-web-terminal'
517519
import VueCodemirror from 'vue-codemirror'
518520
import 'codemirror/lib/codemirror.css'
519521
import 'codemirror/theme/darcula.css'
520522
import 'codemirror/mode/clike/clike.js'
521523
import 'codemirror/addon/edit/closebrackets.js'
522524

523525
Vue.use(VueCodemirror)
524-
Vue.use(Terminal, {
525-
codemirror: {
526-
tabSize: 4,
527-
mode: 'text/x-java',
528-
theme: "darcula",
529-
lineNumbers: true,
530-
line: true,
531-
smartIndent: true
532-
}
526+
Vue.use(Terminal)
527+
configCodemirror({
528+
tabSize: 4,
529+
mode: 'text/x-java',
530+
theme: "darcula",
531+
lineNumbers: true,
532+
line: true,
533+
smartIndent: true
533534
})
534535
```
535536

src/common/api/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ function getOptions(): Options {
3636
return data.options as Options
3737
}
3838

39+
function setOptions(op: Options) {
40+
data.options = {...op}
41+
}
42+
3943
export {
4044
register,
4145
unregister,
4246
rename,
4347
configHighlight,
4448
configCodemirror,
45-
getOptions
49+
getOptions,
50+
setOptions
4651
}
4752

4853
export default new TerminalApi(data)

src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import './css/style.css'
44
import 'vue-json-viewer/style.css'
55
import type {App} from 'vue'
66
import TerminalStore from "./common/store"
7-
import TerminalApi from "./common/api"
7+
import TerminalApi, {setOptions} from "./common/api"
88
import {configHighlight, configCodemirror, rename} from "./common/api"
99
import Terminal from "./Terminal.vue"
10-
import {TerminalAsk, TerminalFlash} from "./types"
10+
import {Options, TerminalAsk, TerminalFlash} from "./types"
1111

12-
Terminal.install = (app: App): void => {
12+
Terminal.install = (app: App, options: Options): void => {
13+
setOptions(options)
14+
// 兼容老版本
15+
Terminal.$api = TerminalApi
16+
Terminal.$Flash = TerminalFlash
17+
Terminal.$Ask = TerminalAsk
1318
app.component(Terminal.__name as string, Terminal)
1419
}
1520

@@ -27,3 +32,8 @@ export {
2732
}
2833

2934
export default Terminal
35+
36+
// 兼容老版本
37+
export const api = TerminalApi
38+
export const Flash = TerminalFlash
39+
export const Ask = TerminalAsk

0 commit comments

Comments
 (0)