使用fc-designer回显表单

在这里插入图片描述

<template>
    <fc-designer ref="designer" :config="config" @save="handleSave" />
</template>

<script setup>
import { ref, nextTick, onMounted } from 'vue'
import { formCreate } from '@form-create/designer'

const designer = ref(null)

onMounted(() => {
    // 正确格式:rule 是数组,options 是对象
    const ruleJson = formCreate.toJson(
        [
            {
                type: 'input',
                field: 'Fv1fm9qur3drabc',
                title: '输入框',
                info: '',
                $required: false,
                _fc_id: 'id_Fx6mm9qur3dracc',
                name: 'ref_Fpabm9qur3dradc',
                display: true,
                hidden: false,
                _fc_drag_tag: 'input',
            }
        ]
    )

    const optionsJson = formCreate.toJson({
        form: {
            inline: false,
            hideRequiredAsterisk: false,
            labelPosition: 'right',
            size: 'default',
            labelWidth: '125px'
        },
        resetBtn: {
            show: false,
            innerText: '重置'
        },
        submitBtn: {
            show: true,
            innerText: '提交'
        }
    }
    )

    nextTick(() => {
        if (designer.value) {
          
            designer.value.setRule(ruleJson)
            designer.value.setOptions(optionsJson)
        }
    })
})

// 表单保存事件
function handleSave({ rule, options }) {
    console.log('表单保存成功', rule)
    console.log('表单保存成功 options', options)

    // 示例:调用接口保存
    // axios.post('/api/saveForm', {
    //   rules: rule,
    //   options: options
    // }).then(() => {
    //   console.log('保存成功')
    // }).catch(error => {
    //   console.error('保存失败', error)
    // })
}

// 控制设计器按钮
const config = {
    showSaveBtn: true
}


</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值