wangzhibo
6 天以前 7bd866831780abcf5a59c4cbb7d1be456eea7c99
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { defineComponent, h, resolveComponent, ref, reactive, watch } from 'vue';
import { isComponent } from '/@/cool/utils';
import { assign } from 'lodash-es';
import { useI18n } from 'vue-i18n';
 
export default defineComponent({
    name: 'cl-editor',
 
    props: {
        name: {
            type: String,
            required: true
        }
    },
 
    setup(props, { slots, expose }) {
        const Editor = ref();
        const ex = reactive({});
        const { t } = useI18n();
 
        watch(Editor, v => {
            if (v) {
                assign(ex, v);
            }
        });
 
        expose(ex);
 
        return () => {
            return isComponent(props.name) ? (
                h(
                    resolveComponent(props.name),
                    {
                        ...props,
                        ref: Editor
                    },
                    slots
                )
            ) : (
                <el-input type="textarea" rows={4} placeholder={t('请输入')} {...props} />
            );
        };
    }
});