73 lines
1.4 KiB
Vue
73 lines
1.4 KiB
Vue
<template>
|
|
<div class="demo">
|
|
<div class="bar">
|
|
<t-button size="small" theme="primary" @click="readValue">读取内容</t-button>
|
|
<t-button size="small" variant="outline" @click="openSearch">打开查找</t-button>
|
|
<span class="status" v-text="status" />
|
|
</div>
|
|
<div class="box">
|
|
<code-editor
|
|
ref="editorRef"
|
|
v-model="code"
|
|
language="typescript"
|
|
placeholder="请输入代码"
|
|
@change="onChange"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from "vue";
|
|
import { CodeEditor } from "timi-tdesign-pc";
|
|
import type { CodeEditorExpose } from "timi-tdesign-pc";
|
|
|
|
const DEMO_CODE = `type DemoUser = {
|
|
id: string;
|
|
name: string;
|
|
};
|
|
|
|
const user: DemoUser = {
|
|
id: "demo-001",
|
|
name: "Timi"
|
|
};
|
|
|
|
console.log(user.name);`;
|
|
|
|
const code = ref(DEMO_CODE);
|
|
const status = ref("等待操作");
|
|
const editorRef = ref<CodeEditorExpose>();
|
|
|
|
function onChange(value: string) {
|
|
status.value = `内容已更新,${value.length} 个字符`;
|
|
}
|
|
|
|
function readValue() {
|
|
status.value = `当前共 ${code.value.length} 个字符`;
|
|
}
|
|
|
|
function openSearch() {
|
|
editorRef.value?.openSearch(true);
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.demo {
|
|
.bar {
|
|
display: flex;
|
|
gap: .5rem;
|
|
align-items: center;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.status {
|
|
font-size: .75rem;
|
|
color: var(--td-text-color-secondary);
|
|
}
|
|
|
|
.box {
|
|
height: 20rem;
|
|
}
|
|
}
|
|
</style>
|