elementui 之el-table 实现批量删除功能

页面前端效果展示:

elementui 之el-table 实现批量删除功能_第1张图片

elementui 之el-table 实现批量删除功能_第2张图片

模板定义(template)

 
            
                        
                        
                        
                        
                        
                        
                        
                        
                         
                        
                        
                        
                            
                        
                    
                    

重点代码:在el-table 添加

 
 

为批量删除按钮添加delArray() 方法,在methods 定义批量删除方法:

  // 批量删除方法
      delArray: function() {
        const length = this.multipleSelection.length;

				for (let i = 0; i < length; i++) {
					  this.delarr.push(this.multipleSelection[i].id);
        }

        if(this.delarr.length > 0) {
          var strs = this.delarr.join(",")
          this.$axios({
            method:'post',
            url:'/api/notice/batchDelete',
            data:{'ids': strs},
            headers:{
                'Content-Type':'application/json;charset=utf-8'      //改这里就好了
            }
        }).then(res => {
          this.$message.success('批量删除成功')
          this.init()
        })
          .catch(function (error) {
            console.log(error)
          })
        }
      },

SpringBoot + MybatisPlus 批量删除方法:

@ApiOperation(httpMethod = "POST", value = "批量通知删除")
	@RequestMapping(value = "/batchDelete", method = { RequestMethod.POST }, produces = "application/json;charset=UTF-8")
	public Result delete(@RequestBody Map paramter) {
		if(paramter.get("ids") != null) {
			String sids = (String) paramter.get("ids");
			if (StringUtils.isNotEmpty(sids)) {			
				baoanNoticeService.removeByIds(Arrays.asList(sids.split(",")));
				return Result.ok();
			}
		}
		
		return Result.error("请求参数缺失Sids");
	}

 

你可能感兴趣的:(vue)