未验证 提交 8c2491fc 编写于 作者: J jinmao88 提交者: GitHub

fix: fix AppendFormDemo (#505)

Co-authored-by: weixin_43658793's avatarhaha <admin@qq.com>
上级 85b92a9a
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
<CollapseContainer title="表单增删"> <CollapseContainer title="表单增删">
<BasicForm @register="register" @submit="handleSubmit"> <BasicForm @register="register" @submit="handleSubmit">
<template #add="{ field }"> <template #add="{ field }">
<Button v-if="field === 1" @click="add">+</Button> <Button v-if="Number(field) === 0" @click="add">+</Button>
<Button v-if="field > 1" @click="del(field)">-</Button> <Button v-if="field > 0" @click="del(field)">-</Button>
</template> </template>
</BasicForm> </BasicForm>
</CollapseContainer> </CollapseContainer>
...@@ -24,25 +24,25 @@ ...@@ -24,25 +24,25 @@
const [register, { appendSchemaByField, removeSchemaByFiled, validate }] = useForm({ const [register, { appendSchemaByField, removeSchemaByFiled, validate }] = useForm({
schemas: [ schemas: [
{ {
field: 'field1a', field: 'field0a',
component: 'Input', component: 'Input',
label: '字段1', label: '字段0',
colProps: { colProps: {
span: 8, span: 8,
}, },
required: true, required: true,
}, },
{ {
field: 'field1b', field: 'field0b',
component: 'Input', component: 'Input',
label: '字段1', label: '字段0',
colProps: { colProps: {
span: 8, span: 8,
}, },
required: true, required: true,
}, },
{ {
field: '1', field: '0',
component: 'Input', component: 'Input',
label: ' ', label: ' ',
colProps: { colProps: {
...@@ -64,14 +64,14 @@ ...@@ -64,14 +64,14 @@
} }
} }
const n = ref(2); const n = ref(1);
function add() { function add() {
appendSchemaByField( appendSchemaByField(
{ {
field: 'field' + n.value + 'a', field: `field${n.value}a`,
component: 'Input', component: 'Input',
label: '字段2', label: '字段' + n.value,
colProps: { colProps: {
span: 8, span: 8,
}, },
...@@ -81,9 +81,9 @@ ...@@ -81,9 +81,9 @@
); );
appendSchemaByField( appendSchemaByField(
{ {
field: 'field' + n.value + 'b', field: `field${n.value}b`,
component: 'Input', component: 'Input',
label: '字段2', label: '字段' + n.value,
colProps: { colProps: {
span: 8, span: 8,
}, },
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
}, },
'' ''
); );
appendSchemaByField( appendSchemaByField(
{ {
field: `${n.value}`, field: `${n.value}`,
...@@ -107,8 +108,8 @@ ...@@ -107,8 +108,8 @@
} }
function del(field) { function del(field) {
console.log(field);
removeSchemaByFiled([`field${field}a`, `field${field}b`, `${field}`]); removeSchemaByFiled([`field${field}a`, `field${field}b`, `${field}`]);
n.value--;
} }
return { register, handleSubmit, add, del }; return { register, handleSubmit, add, del };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册