vue table增删改查input框

在这里插入图片描述

                    <div class="div-card" >
                      <template>
                        <el-table :data="proGroupTable[indexes].modelPropertyItemBOList" border stripe style="width: 100%;"  >
                          <el-table-column prop="id" label="id" align="center"v-show="false">
                          </el-table-column>
                          <el-table-column prop="propertySequence" label="顺序" align="center">
                            <template slot-scope="scope">
                              <span v-if="paramEditFlag[indexes]==false">{{scope.row.propertySequence}}</span>
                              <el-input v-else-if="paramEditFlag[indexes]==true || scope.row.propertySequence" v-model="scope.row.propertySequence"></el-input>
                            </template>
                          </el-table-column>
                          <el-table-column prop="propertyName" label="属性名" align="center">
                            <template slot-scope="scope" >
                              <span v-if="paramEditFlag[indexes]==false">{{scope.row.propertyName}}</span>
                              <el-input v-else-if="paramEditFlag[indexes]==true || scope.row.propertyName" v-model="scope.row.propertyName"></el-input>
                            </template>
                          </el-table-column>
                          <el-table-column prop="propertyQualifier" label="标识符" align="center">
                            <template slot-scope="scope">
                              <span v-if="paramEditFlag[indexes]==false">{{scope.row.propertyQualifier}}</span>
                              <el-input v-else-if="paramEditFlag[indexes]==true || scope.row.propertyQualifier" v-model="scope.row.propertyQualifier"></el-input>
                            </template>
                          </el-table-column>
                          <el-table-column prop="propertyType" label="参数类型" align="center">
                            <template slot-scope="scope">
                              <span v-if="paramEditFlag[indexes]==false">{{scope.row.propertyType}}</span>
                              <el-input v-else-if="paramEditFlag[indexes]==true || scope.row.propertyType" v-model="scope.row.propertyType"></el-input>
                            </template>
                          </el-table-column>
                          <el-table-column prop="accuracy" label="精度" align="center">
                            <template slot-scope="scope">
                              <span v-if="paramEditFlag[indexes]==false">{{scope.row.accuracy}}</span>
                              <el-input v-else-if="paramEditFlag[indexes]==true || scope.row.accuracy" v-model="scope.row.accuracy"></el-input>
                            </template>
                          </el-table-column>
                          <el-table-column prop="unit" label="单位" align="center">
                            <template slot-scope="scope">
                              <span v-if="paramEditFlag[indexes]==false">{{scope.row.unit}}</span>
                              <el-input v-else-if="paramEditFlag[indexes]==true || scope.row.unit" v-model="scope.row.unit"></el-input>
                            </template>
                          </el-table-column>
                          <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                              <el-button type="text" size="medium" @click="deleteParam(scope.row,scope.$index,indexes)">
                                <i class="el-icon-delete" aria-hidden="true"></i>
                              </el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                      </template>
                    </div>
                    <div style="text-align: center">
                      <el-button type="text" @click="addParam(indexes)">增加</el-button>
                      <el-button type="text" @click="saveParam(indexes)">保存</el-button>
                      <el-button type="text" @click="editParam(indexes)">修改</el-button>
                      <el-button type="text" @click="delParamGroup(indexes)">删除</el-button>
                    </div>

addParam(indexes){
      Vue.set(this.paramEditFlag,indexes,true)
        this.proGroupTable[indexes].modelPropertyItemBOList.push({
        edit:true
      })

    }
editParam(indexes){
   Vue.set(this.paramEditFlag,indexes,true)
}
    saveParam(indexes) {
      Vue.set(this.paramEditFlag,indexes,false)

      var modelPropertyItemList= [];
      var modelPropertyGroupParam= {};
      for (var i=0;i<this.proGroupTable[indexes].modelPropertyItemBOList.length;i++){
        var mPro = {};
        mPro["id"]=this.proGroupTable[indexes].modelPropertyItemBOList[i].id;
        mPro["groupId"]=this.proGroupTable[indexes].id;
        mPro["accuracy"]=this.proGroupTable[indexes].modelPropertyItemBOList[i].accuracy;
        mPro["propertyName"]=this.proGroupTable[indexes].modelPropertyItemBOList[i].propertyName;
        mPro["propertyQualifier"]=this.proGroupTable[indexes].modelPropertyItemBOList[i].propertyQualifier;
        mPro["propertyType"]=this.proGroupTable[indexes].modelPropertyItemBOList[i].propertyType;
        mPro["propertySequence"]=this.proGroupTable[indexes].modelPropertyItemBOList[i].propertySequence;
        mPro["unit"]=this.proGroupTable[indexes].modelPropertyItemBOList[i].unit;
        modelPropertyItemList.push(mPro);
      }

      modelPropertyGroupParam["id"] = this.proGroupTable[indexes].id;
      modelPropertyGroupParam["modelId"] =this.proGroupTable[indexes].modelId;
      modelPropertyGroupParam["groupName"] =this.proGroupTable[indexes].groupName;
      modelPropertyGroupParam["groupQualifier"] =this.proGroupTable[indexes].groupQualifier;
      modelPropertyGroupParam["category"] =this.cValue;

      modelPropertyGroupParam["modelPropertyItemList"] = modelPropertyItemList;
      console.log("---保存属性----")
      savePro(modelPropertyGroupParam).then(response =>{
      });

    },
    
//删除属性行
deleteParam(row,index,indexes) {
	this.proGroupTable[indexes].modelPropertyItemBOList.splice(index, 1);
},
//删除属性组
      delParamGroup(indexes) {
        this.$confirm('此操作将永久删除该属性组, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          var groupId = this.proGroupTable[indexes].id;
          proDelete(groupId).then(res => {
            if (res.success == true) {
              this.propertyDetail();
              this.$message({
                message: '删除成功',
                type: 'success'
              });
            } else {
              this.$message({
                message: res.errMsg,
                type: 'error'
              });
            }
          })
        })
      },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot和Vue.js可以很好地搭配使用,实现前后端分离的Web应用程序。以下是一个简单的例子,演示如何使用Spring Boot和Vue.js实现增删改查功能。 1. 创建一个Spring Boot项目,包含Spring Web和Spring Data JPA依赖。创建一个实体类和一个Repository接口,用于操作数据库。 ```java @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private String email; // 省略getter和setter } @Repository public interface UserRepository extends JpaRepository<User, Long> { } ``` 2. 创建一个RESTful API,使用Spring MVC和Spring Data REST实现,用于获取、创建、更新和删除用户。 ```java @RestController @RequestMapping("/api/users") public class UserController { @Autowired private UserRepository userRepository; @GetMapping public List<User> findAll() { return userRepository.findAll(); } @PostMapping public User create(@RequestBody User user) { return userRepository.save(user); } @PutMapping("/{id}") public User update(@PathVariable Long id, @RequestBody User user) { user.setId(id); return userRepository.save(user); } @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { userRepository.deleteById(id); } } ``` 3. 创建一个Vue.js应用程序,使用axios库与后端进行通信。创建一个组件,用于显示用户列表,以及一个表单组件,用于创建或更新用户。 ```html <template> <div> <table> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Actions</th> </tr> <tr v-for="user in users" :key="user.id"> <td>{{ user.id }}</td> <td>{{ user.name }}</td> <td>{{ user.email }}</td> <td> <button @click="edit(user)">Edit</button> <button @click="remove(user)">Remove</button> </td> </tr> </table> <form v-if="editing" @submit.prevent="save"> <input type="text" v-model="user.name" placeholder="Name"> <input type="email" v-model="user.email" placeholder="Email"> <button type="submit">{{ editing.id ? 'Update' : 'Create' }}</button> </form> </div> </template> <script> import axios from 'axios'; export default { data() { return { users: [], user: {}, editing: false, }; }, methods: { async fetchUsers() { const { data } = await axios.get('/api/users'); this.users = data; }, async save() { if (this.editing.id) { await axios.put(`/api/users/${this.editing.id}`, this.user); } else { await axios.post('/api/users', this.user); } this.editing = false; this.user = {}; await this.fetchUsers(); }, async remove(user) { await axios.delete(`/api/users/${user.id}`); await this.fetchUsers(); }, edit(user) { this.editing = true; this.user = { ...user }; }, }, async mounted() { await this.fetchUsers(); }, }; </script> ``` 4. 在Spring Boot应用程序中配置静态资源路径,将Vue.js应用程序打包为静态资源,并在Spring Boot应用程序中提供静态资源服务。 ```properties spring.mvc.static-path-pattern=/static/** spring.resources.static-locations=classpath:/static/ ``` 5. 打包Vue.js应用程序,并将生成的dist目录复制到Spring Boot应用程序的静态资源目录中。 6. 运行Spring Boot应用程序,访问http://localhost:8080/static/index.html即可看到用户列表和表单。现在可以使用Vue.js应用程序与后端进行交互,实现增删改查功能了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值