vue table增删改查input框之校验必填项

在这里插入图片描述

          <el-form :model="testForm" ref="testForm" :rules="testFormRules" label-width="100px" :inline="true">

            <el-form-item label="属性组名:" prop="testFormGroupName">
              <el-input placeholder="请输入内容" v-model="testForm.testFormGroupName" maxlength="32"></el-input>
            </el-form-item>

            <el-form-item label="组标识符:" prop="testFormQualifier">
              <el-input placeholder="请输入内容" v-model="testForm.testFormQualifier" maxlength="32"></el-input>
            </el-form-item>

            <el-form-item label="组类型:" prop="testFormType">
              <el-select v-model="testForm.testFormType" placeholder="请选择" @change="getMoreGroupTypeValue">
                <el-option v-for="item in groupTypeTable" :key="item.value" :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-form>

          <!--新增属性组弹框---table-->
          <div class="div-card" style="background-color: #f2f2f2;">
            <div class="div-card">
              <template>

                <el-form ref="form" :rules="rulesPro" :model="form">

                  
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基于Vue增删改查示例,包含了对应的函数调用: ```html <template> <div> <h2>用户管理</h2> <table> <thead> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="user in users" :key="user.id"> <td>{{ user.id }}</td> <td>{{ user.name }}</td> <td>{{ user.age }}</td> <td> <button @click="editUser(user)">编辑</button> <button @click="deleteUser(user)">删除</button> </td> </tr> </tbody> </table> <form v-if="showForm" @submit.prevent="saveUser"> <h3>{{ formTitle }}</h3> <label for="name">姓名:</label> <input type="text" id="name" v-model="currentUser.name" required> <label for="age">年龄:</label> <input type="number" id="age" v-model="currentUser.age" required> <button type="submit">{{ formSubmitLabel }}</button> <button type="button" @click="cancelEdit">取消</button> </form> <button @click="addUser">添加用户</button> </div> </template> <script> export default { data() { return { users: [ { id: 1, name: '张三', age: 20 }, { id: 2, name: '李四', age: 25 }, { id: 3, name: '王五', age: 30 } ], showForm: false, formTitle: '', formSubmitLabel: '', currentUser: { id: null, name: '', age: null } } }, methods: { addUser() { this.currentUser = { id: null, name: '', age: null } this.formTitle = '添加用户' this.formSubmitLabel = '添加' this.showForm = true }, editUser(user) { this.currentUser = { ...user } this.formTitle = '编辑用户' this.formSubmitLabel = '保存' this.showForm = true }, deleteUser(user) { const index = this.users.findIndex(u => u.id === user.id) this.users.splice(index, 1) }, saveUser() { if (this.currentUser.id === null) { // 添加用户 this.currentUser.id = this.users.length + 1 this.users.push({ ...this.currentUser }) } else { // 修改用户 const index = this.users.findIndex(u => u.id === this.currentUser.id) this.users.splice(index, 1, { ...this.currentUser }) } this.showForm = false }, cancelEdit() { this.showForm = false } } } </script> ``` 在上面的示例代码中,我们定义了一个 `users` 数组来存储用户数据,同时定义了一些用于增删改查操作的方法: - `addUser`:添加用户操作,将 `currentUser` 对象重置为初始值并显示表单; - `editUser`:编辑用户操作,将 `currentUser` 对象设置为要编辑的用户并显示表单; - `deleteUser`:删除用户操作,根据用户ID从 `users` 数组中删除对应的用户; - `saveUser`:保存用户操作,根据 `currentUser` 对象来判断是添加用户还是修改用户,并将用户数据更新到 `users` 数组中; - `cancelEdit`:取消编辑操作,将 `showForm` 属性设置为 `false` 隐藏表单。 在模板中,我们通过 `v-for` 指令来遍历 `users` 数组并显示用户数据,同时为每个用户添加编辑和删除按钮。当需要添加或编辑用户时,会显示一个表单来输入用户信息,保存或取消操作后表单会隐藏。 需要注意的是,以上示例代码仅供参考,实际开发中还需要考虑一些其他的情况,如数据校验、错误处理等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值