Skip to content
On this page

代码视图

何时使用

在有需要进行文字展示且文字内容是代码时,使用该组件可以提供代码高亮、行号、复制

代码演示

<template>
  <h-code :code="textInput" lang="TYPESCRIPT" />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const textInput = ref(`function likeUserAgent(str: string): boolean {
  return (
    str.includes('Mozilla') ||
    str.includes('Opera') ||
    str.includes('Dalvik') ||
    str.includes('AppleTV') ||
    str.includes('Windows') ||
    str.includes('Mac') ||
    str.includes('Linux') ||
    str.includes('Android') ||
    str.includes('Chromium') ||
    str.includes('Electron') ||
    str.includes('Gecko')
  );
}
export function isUserAgent(value) {
  return likeUserAgent(value);
}`);
</script>

API

属性

属性说明类型默认值
code展示一段可复制的代码段string
lang编程语言,字母需全部大写CodeEditorLanguagesUnio