介绍
本文档主要用于描述 fnToString
函数和 fnToFunction
函数的一些功能和用法。
fnToString
使用 fnToString
函数将函数转换为字符串。
查看代码
vue
<template>
<ShadcnText>Convert response:</ShadcnText>
<ShadcnText type="code">{{ value }}</ShadcnText>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { fnToString } from 'view-shadcn-ui'
const fn = { formatter: (value) => `${ value }px` }
const value = ref({ formatter: fnToString(fn.formatter) })
</script>
fnToFunction
使用 fnToFunction
函数将字符串转换为函数。
显示代码
vue
<template>
<ShadcnText>Convert response:</ShadcnText>
<ShadcnText type="code">{{ value }}</ShadcnText>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { fnToFunction } from 'view-shadcn-ui'
const fn = { "formatter": "(value) => `${value}px`" }
const value = ref({ formatter: fnToFunction(fn.formatter) })
</script>