-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
686 additions
and
2,036 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<template> | ||
<nut-form> | ||
<nut-form-item label="姓名"> | ||
<nut-input v-model="formData.name" placeholder="请输入姓名" type="text" /> | ||
</nut-form-item> | ||
<nut-form-item label="年龄"> | ||
<nut-input v-model="formData.age" placeholder="请输入年龄" type="text" /> | ||
</nut-form-item> | ||
<nut-form-item label="联系电话"> | ||
<nut-input v-model="formData.tel" placeholder="请输入联系电话" type="text" /> | ||
</nut-form-item> | ||
<nut-form-item label="地址"> | ||
<nut-input v-model="formData.addr" placeholder="请输入地址" type="text" /> | ||
</nut-form-item> | ||
<nut-form-item label="备注"> | ||
<nut-textarea v-model="formData.info" placeholder="请输入备注" type="text" /> | ||
</nut-form-item> | ||
</nut-form> | ||
</template> | ||
<script setup> | ||
import { ref } from 'vue'; | ||
const formData = ref({ | ||
name: '', | ||
age: '', | ||
tel: '', | ||
addr: '', | ||
info: '' | ||
}); | ||
</script> |
57 changes: 57 additions & 0 deletions
57
packages/nutui-taro-demo/src/dentry/pages/form/dynamic.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<template> | ||
<nut-form ref="formRef" :model-value="formData"> | ||
<nut-form-item label="姓名" prop="name" required :rules="[{ required: true, message: '请填写姓名' }]"> | ||
<nut-input v-model="formData.name" placeholder="请输入姓名" type="text" /> | ||
</nut-form-item> | ||
<nut-form-item | ||
v-for="(item, index) in formData.tels" | ||
:key="item.key" | ||
:label="'字段 ' + index" | ||
:prop="'tels.' + index + '.value'" | ||
required | ||
:rules="[{ required: true, message: '请填写字段 ' + index }]" | ||
> | ||
<nut-input v-model="item.value" :placeholder="'请输入字段 ' + index" type="text" /> | ||
</nut-form-item> | ||
<nut-space style="margin: 10px"> | ||
<nut-button size="small" @click="add">添加</nut-button> | ||
<nut-button size="small" @click="remove">删除</nut-button> | ||
<nut-button size="small" type="primary" @click="submit">提交</nut-button> | ||
<nut-button size="small" @click="reset">重置提示状态</nut-button> | ||
</nut-space> | ||
</nut-form> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue'; | ||
const formData = ref({ | ||
name: '', | ||
tels: [] | ||
}); | ||
const formRef = ref(null); | ||
const add = () => { | ||
formData.value.tels.push({ | ||
key: Date.now(), | ||
value: '' | ||
}); | ||
}; | ||
const remove = () => { | ||
formData.value.tels.pop(); | ||
}; | ||
const submit = () => { | ||
formRef.value?.validate().then(({ valid, errors }) => { | ||
if (valid) { | ||
console.log('success:', formData.value); | ||
} else { | ||
console.warn('error:', errors); | ||
} | ||
}); | ||
}; | ||
const reset = () => { | ||
formRef.value?.reset(); | ||
}; | ||
</script> |
Oops, something went wrong.