wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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
import { defineComponent, type PropType } from 'vue';
import { computed, useModel } from 'vue';
 
export default defineComponent({
    name: 'cl-text',
 
    props: {
        modelValue: null,
        formatter: Function as PropType<(value: any, scope: any) => string>
        // 继承 el-text https://element-plus.org/zh-CN/component/text.html#attributes
    },
 
    setup(props) {
        const value = useModel(props, 'modelValue');
 
        const text = computed(() => {
            if (props.formatter) {
                return props.formatter(value.value, props);
            }
 
            return value.value;
        });
 
        return () => {
            return <el-text>{text.value}</el-text>;
        };
    }
});