99npm安装vue-web-terminal
1010
1111``` shell
12- npm install vue-web-terminal --save
12+ // vue2安装
13+ npm install vue-web-terminal@2.xx --save
14+
15+ // vue3安装
16+ npm install vue-web-terminal@3.xx --save
1317```
1418
1519main.js中载入 Terminal 插件
1620
1721``` js
1822import Terminal from ' vue-web-terminal'
1923
24+ // for vue2
2025Vue .use (Terminal)
26+
27+ // for vue3
28+ const app = createApp (App)
29+ app .use (Terminal)
2130```
2231
2332使用示例
2433
2534``` vue
26-
2735<template>
2836 <div id="app">
2937 <terminal name="my-terminal" @execCmd="onExecCmd"></terminal>
3038 </div>
3139</template>
3240
3341<script>
42+ import Terminal from "vue-web-terminal"
3443
3544export default {
3645 name: 'App',
46+ components:{Terminal},
3747 methods: {
3848 onExecCmd(key, command, success, failed) {
3949 if (key === 'fail') {
@@ -115,7 +125,7 @@ terminal标签支持属性参数表
115125| warnLogLimitEnable | 是否开启日志限制警告 | boolean | true |
116126| auto-help | 是否打开命令行自动搜索提示功能 | boolean | true |
117127| help-style | help自定义样式 | string | |
118- | command-store | 自定义的命令行库 ,见[ 命令行定义格式 ] ( #命令行定义 ) | array | [ 内置命令行] ( #内置命令行 ) |
128+ | command-store | 自定义的命令库 ,见[ 命令定义格式 ] ( #命令定义 ) | array | [ 内置命令行] ( #内置命令行 ) |
119129| command-store-sort | 命令行库排序 | function | function(a,b) {} |
120130
121131## Select Events
@@ -133,14 +143,11 @@ terminal标签支持事件表
133143
134144本插件提供了一些 Api 可以使用 Vue 主动向插件发起事件请求。
135145
136- Terminal在 Vue 的prototype中定义了一个变量可以获取Terminal对象
137-
138146``` js
139- this . $ terminal
147+ import Terminal from " vue-web- terminal"
140148
141- // or
142-
143- Vue .prototype .$terminal
149+ // 获取api
150+ Terminal .$api
144151```
145152
146153### 向Terminal推送一条消息
@@ -153,22 +160,23 @@ let message = {
153160 content: ' This is a wanning message.'
154161}
155162
156- this . $terminal .pushMessage (name, message)
163+ Terminal . $api .pushMessage (name, message)
157164```
158165
159166### 修改上下文
160167
161168比如当前输入行` $ /vue-web-terminal/tzfun > ` 的 * /vue-web-terminal/tzfun* 就是上下文,上下文文本可以由开发者自由设置 ,但是需使用` .sync ` 绑定一个变量
162169
163170``` vue
164-
165171<template>
166172 <div id="app">
167173 <terminal name="my-terminal" :context.sync="context"></terminal>
168174 </div>
169175</template>
170176
171177<script>
178+ import Terminal from "vue-web-terminal"
179+
172180export default {
173181 name: 'App',
174182 data() {
@@ -178,7 +186,7 @@ export default {
178186 },
179187 methods: {
180188 _updateContext(newCtx) {
181- this.$terminal .updateContext("my-terminal", newCtx)
189+ Terminal.$api .updateContext("my-terminal", newCtx)
182190 }
183191 }
184192}
@@ -344,22 +352,22 @@ execCmd(key, command, success)
344352}
345353```
346354
347- ## 命令行定义
355+ ## 命令定义
348356
349- 如果开启了命令行帮助搜索功能,在实例化Terminal之前需要传入自定义命令行库,传入的命令行库为 N 个命令行的数组,以下是命令行格式定义规则 :
357+ 如果开启了命令帮助搜索功能,在实例化Terminal之前需要传入自定义命令库,传入的命令库为 N 个命令的数组,以下是命令格式定义规则 :
350358
351- | 参数 | 说明 | 类型 |
352- | -------------| --------------------------- | --------|
353- | key | 命令行关键字 ,必填 | string |
354- | title | 显示标题 | string |
355- | group | 分组,可自定义,默认为 ` local ` | string |
356- | usage | 使用方法 | string |
357- | description | 详细描述 | string |
358- | example | 使用示例,见[ 命令行示例格式 ] ( #命令行示例格式 ) | array |
359+ | 参数 | 说明 | 类型 |
360+ | -------------| -------------------------| --------|
361+ | key | 命令关键字 ,必填 | string |
362+ | title | 显示标题 | string |
363+ | group | 分组,可自定义,默认为 ` local ` | string |
364+ | usage | 使用方法 | string |
365+ | description | 详细描述 | string |
366+ | example | 使用示例,见[ 命令示例格式 ] ( #命令示例格式 ) | array |
359367
360- ### 命令行示例格式
368+ ### 命令示例格式
361369
362- 示例格式比较简单,` des ` 为描述,` cmd ` 为具体的命令行 ,json格式如下:
370+ 示例格式比较简单,` des ` 为描述,` cmd ` 为具体的命令 ,json格式如下:
363371
364372``` json
365373[
@@ -374,7 +382,7 @@ execCmd(key, command, success)
374382]
375383```
376384
377- ### 内置命令行
385+ ### 内置命令
378386
379387Terminal默认内置有以下命令,且不可替代
380388
0 commit comments