×
全部 > AI技术 > AI编程 > AI代码生成 > 生成Vue表单代码

生成Vue表单代码

DeepSeek V3(Deepseek)

```markdown # 表单代码生成报告 ## Form Overview - 框架类型:Vue 3 - 字段数量:3个(用户名、邮箱、性别) - 必填字段:3个 - 包含字段类型:文本输入、邮箱输入、下拉选择 ## Field List | 字段名 | 类型 | 必填 | 占位提示 | 选项 | |----------|---------|------|----------------|-----------| | username | text | 是 | 请输入用户名 | - | | email | email | 是 | 请输入邮箱 | - | | gender | select | 是 | - | ["男","女"]| ## Form Source Code (Vue 3) ```vue <template> <form @submit.prevent="handleSubmit"> <!-- 用户名字段 --> <div class="form-group"> <label for="username">用户名</label> <input type="text" id="username" v-model="formData.username" :placeholder="placeholder.username" required class="form-control" /> </div> <!-- 邮箱字段 --> <div class="form-group"> <label for="email">邮箱</label> <input type="email" id="email" v-model="formData.email" :placeholder="placeholder.email" required class="form-control" /> </div> <!-- 性别字段 --> <div class="form-group"> <label for="gender">性别</label> <select id="gender" v-model="formData.gender" required class="form-control" > <option disabled value="">请选择</option> <option v-for="option in options.gender" :key="option" :value="option"> {{ option }} </option> </select> </div> <button type="submit" class="submit-btn">提交</button> </form> </template> <script> import { reactive } from 'vue'; export default { setup() { const formData = reactive({ username: '', email: '', gender: '' }); const placeholder = { username: '请输入用户名', email: '请输入邮箱' }; const options = { gender: ['男', '女'] }; const handleSubmit = () => { console.log('表单提交数据:', formData); // 这里添加表单提交逻辑 }; return { formData, placeholder, options, handleSubmit }; } }; </script> <style scoped> .form-group { margin-bottom: 1rem; } label { display: block; margin-bottom: 0.5rem; font-weight: bold; } .form-control { width: 100%; padding: 0.5rem; border: 1px solid #ccc; border-radius: 4px; font-size: 1rem; } .submit-btn { background-color: #4CAF50; color: white; padding: 0.5rem 1rem; border: none; border-radius: 4px; cursor: pointer; font-size: 1rem; } .submit-btn:hover { background-color: #45a049; } </style> ``` ### 功能说明 1. 使用Vue 3的Composition API管理表单状态 2. 表单数据通过`reactive`进行响应式绑定 3. 包含基础样式,可直接使用或覆盖 4. 提交事件已阻止默认行为,需在`handleSubmit`中添加业务逻辑 5. 所有必填字段已添加HTML5原生验证 ```

gpt-4o(OpenAI)

# 表单概述(Form Overview) 该表单旨在收集用户的基本信息,包括用户名、邮箱和性别。 - **用户名**: 必填字段,文本输入。 - **邮箱**: 必填字段,需符合邮箱格式。 - **性别**: 必填字段,从下拉列表中选择。 目标框架为Vue,我们将利用Vue的`v-model`实现数据绑定,并在必要时进行表单验证。 # 表单字段列表(Field List) 1. **用户名** - 标签: 用户名 - 字段名: username - 类型: text - 必填: 是 - 占位符: "请输入用户名" 2. **邮箱** - 标签: 邮箱 - 字段名: email - 类型: email - 必填: 是 - 占位符: "请输入邮箱" 3. **性别** - 标签: 性别 - 字段名: gender - 类型: select - 选项: 男, 女 - 必填: 是 # 表单完整源代码(Form Source Code) ```vue <template> <form @submit.prevent="handleSubmit"> <div> <label for="username">用户名</label> <input id="username" name="username" type="text" v-model="form.username" :placeholder="fields.username.placeholder" required /> </div> <div> <label for="email">邮箱</label> <input id="email" name="email" type="email" v-model="form.email" :placeholder="fields.email.placeholder" required /> </div> <div> <label for="gender">性别</label> <select id="gender" name="gender" v-model="form.gender" required > <option v-for="option in fields.gender.options" :key="option" :value="option"> {{ option }} </option> </select> </div> <button type="submit">提交</button> </form> </template> <script> export default { data() { return { form: { username: '', email: '', gender: '', }, fields: { username: { placeholder: '请输入用户名', }, email: { placeholder: '请输入邮箱', }, gender: { options: ['男', '女'], }, }, }; }, methods: { handleSubmit() { // 表单提交逻辑 console.log('表单提交数据:', this.form); // 处理进一步的验证、发送请求等操作 }, }, }; </script> <style scoped> form { max-width: 400px; margin: 0 auto; } div { margin-bottom: 15px; } label { display: block; margin-bottom: 5px; } input, select, button { width: 100%; padding: 8px; box-sizing: border-box; } button { background-color: #42b983; color: white; border: none; cursor: pointer; } button:hover { background-color: #38a169; } </style> ``` 使用Vue构建表单时,`v-model`可以简化数据的双向绑定。这个表单包括基本的字段验证(例如必填字段),提交时会触发`handleSubmit`方法,可以在其中进一步处理表单数据(如发送到服务器等)。本示例还包含了简单的样式处理,使表单更具可读性和用户友好性。

claude3.5 sonnet 20241022(Anthropic)

## 表单概述 (Form Overview) 本表单用于用户注册,包含用户名、邮箱和性别三个字段。所有字段均为必填项,确保用户提供必要的信息。 ## 表单字段列表 (Field List) - **用户名** - 名称: `username` - 类型: `text` - 必填: 是 - 占位提示: 请输入用户名 - **邮箱** - 名称: `email` - 类型: `email` - 必填: 是 - 占位提示: 请输入邮箱 - **性别** - 名称: `gender` - 类型: `select` - 选项: ["男", "女"] - 必填: 是 ## 表单完整源代码 (Form Source Code) ```vue <template> <form @submit.prevent="handleSubmit"> <div> <label for="username">{{ fields[0].label }}</label> <input v-model="formData.username" type="text" id="username" placeholder="请输入用户名" required /> </div> <div> <label for="email">{{ fields[1].label }}</label> <input v-model="formData.email" type="email" id="email" placeholder="请输入邮箱" required /> </div> <div> <label for="gender">{{ fields[2].label }}</label> <select v-model="formData.gender" id="gender" required> <option disabled value="">请选择性别</option> <option v-for="option in fields[2].options" :key="option" :value="option">{{ option }}</option> </select> </div> <button type="submit">提交</button> </form> </template> <script> export default { data() { return { formData: { username: '', email: '', gender: '' }, fields: [ { label: "用户名", name: "username", type: "text", required: true, placeholder: "请输入用户名" }, { label: "邮箱", name: "email", type: "email", required: true, placeholder: "请输入邮箱" }, { label: "性别", name: "gender", type: "select", options: ["男", "女"], required: true } ] }; }, methods: { handleSubmit() { // 提交表单逻辑 console.log(this.formData); } } }; </script> <style scoped> /* 添加样式以提高表单可用性 */ form div { margin-bottom: 1em; } label { display: block; margin-bottom: 0.5em; } input, select { width: 100%; padding: 0.5em; border: 1px solid #ccc; } button { padding: 0.5em 1em; background-color: #007bff; color: white; border: none; cursor: pointer; } button:hover { background-color: #0056b3; } </style> ``` 以上代码生成了一个符合Vue框架的用户注册表单,包含必要的字段和提交逻辑。

通义千问2.5-Coder-7B(阿里云百炼)

## Form Overview This form is designed to collect user information including username, email, and gender. It is built using Vue 3 with v-model for data binding. ## Field List 1. **Username** - Label: 用户名 - Type: text - Required: Yes - Placeholder: 请输入用户名 2. **Email** - Label: 邮箱 - Type: email - Required: Yes - Placeholder: 请输入邮箱 3. **Gender** - Label: 性别 - Type: select - Options: 男, 女 - Required: Yes ## Form Source Code ```vue <template> <form @submit.prevent="handleSubmit"> <div> <label for="username">用户名</label> <input id="username" v-model="formData.username" type="text" placeholder="请输入用户名" required /> </div> <div> <label for="email">邮箱</label> <input id="email" v-model="formData.email" type="email" placeholder="请输入邮箱" required /> </div> <div> <label for="gender">性别</label> <select id="gender" v-model="formData.gender" required> <option disabled value="">请选择性别</option> <option>男</option> <option>女</option> </select> </div> <button type="submit">提交</button> </form> </template> <script> import { reactive } from 'vue'; export default { setup() { const formData = reactive({ username: '', email: '', gender: '' }); const handleSubmit = () => { // Handle form submission logic here console.log('Form submitted:', formData); }; return { formData, handleSubmit }; } }; </script> <style scoped> /* Add your styles here */ </style> ``` This code snippet provides a complete Vue 3 form component that includes input fields for username, email, and gender, along with validation and submission handling.

模型名称 模型提供商 响应总时长(s) 生成 token 数 首 token 延迟(s) 生成速率(tokens/s)
42.42
825
5.27
19.45
40.58
828
内容最多
5.68
20.41
14.96
0
2.6
0
10.25
响应最快
453
0.54
延迟最小
44.21
速度最快
AI文本生成
38家服务商提供服务
AI深度推理
11家服务商提供服务
AI代码生成
11家服务商提供服务
AI数学模型
10家服务商提供服务