Skip to content
On this page

TextTransform

When To Use

Special component for text conversion (with its own layout), which can be used directly to quickly generate ui layout and simple conversion logic

Examples

Common Transform

output

The general one-input-output form can be passed to the judgment function through the auto fill input condition property to automatically backfill the clipboard

<template>
  <h-text-transform
    :sampleData="sampleData"
    :transform="transform"
    :autoFillInputCondition="isJWT"
  />
</template>

<script setup lang="ts">
const sampleData = 'Example';
const transform = (inputValue: string): string => {
  // do something
  // 将转换结果返回即可在右边进行展示,注意返回结果必须是字符串
  return '';
};
const isJWT = (text: string) => {
  const reg = /^e([A-Za-z0-9_-]+)\.e([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]+)$/;
  return reg.test(text);
};
</script>

File Transform

output

Start the file conversion mode through property enableFile, you can directly import and export the content in the converted file

<template>
  <h-text-transform
    enableFile
    fileOutputAlert="导出成功"
    :transform="transform"
  />
</template>

<script setup lang="ts">
const transform = (inputValue: string): string => {
  // do something
  // 将转换结果返回即可在右边进行展示,注意返回结果必须是字符串
  return '';
};
</script>

Two-way Transform

Start the bidirectional conversion mode through property enableReverse, which can support bidirectional text conversion at the same time

<template>
  <h-text-transform
    enableReverse
    :transform="transform"
    :sampleData="sampleData"
    :reverseTransform="reverseTransform"
  />
</template>

<script setup lang="ts">

const sampleData = 'Example';
const transform = (inputValue: string) => {
  // do something
  return ''
}


const reverseTransform = () => {
  // do something
  // 将转换结果返回即可在左边进行展示,注意返回结果必须是字符串
}

</script>

API

Props

PropertyDescriptionTypedefault
sampleDataInput examplestringA Free, Modern Toolbox Built for Developers.
enableReverseWhether to use inverse conversionbooleanfalse
enableFileWhether to support file conversionbooleanfalse
fileOutputAlertPrompt text after file conversionstring
transformConversion callback functionFunction
reverseTransformInverse conversion callback functionFunction
fileOutputNameoutput file nameFunctionfalse
autoFillInputConditionClipboard automatic backfill judgment functionFunctionnull
saveOptionsAutomatically upload and initialize component data.
Note ⚠️: Multiple key values under the same tool need to be unique.
objectautoSave:false,key:""

Expose

Expose PropertyDescriptionTypedefault
inputValuethe value in the input boxstring
handleChangeConversion functions, which can be used to perform conversions manuallyFunction

Slot

Slot NameDescriptionTypedefault
optionTransform options slot between input and output boxesComponent