npm i vue-web-terminal
main.ts
1 2 3 4 5 6 7 8 9 10 11 |
import { createApp } from "vue"; import "./style.css"; import App from "./App.vue"; import { createTerminal } from 'vue-web-terminal' const app = createApp(App) app.use(createTerminal()) // Mount the app app.mount("#app"); |
App.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<script setup lang="ts"> import {Terminal, DragConfig, FailedFunc, SuccessFunc, TerminalMessageClass} from 'vue-web-terminal'; import {reactive} from "vue"; const dragConf = reactive<DragConfig>({ width: "50%", height: "70%", zIndex: 100, init: { x: 200, y: 200 }, pinned: false }) const onExecCmd = (key: string, command: string, success: SuccessFunc, failed: FailedFunc) => { if (key === 'fail') { failed('Something wrong!!!') } else { let allClass = ['success', 'error', 'system', 'info', 'warning']; let clazz = allClass[Math.floor(Math.random() * allClass.length)]; success({ type: 'normal', class: clazz as TerminalMessageClass, tag: clazz, content: `Your command is '${command}'` }) } } </script> <template> <terminal name="my-terminal" theme="dark" @exec-cmd="onExecCmd" :drag-conf="dragConf" /> </template> <style scoped> </style> |