DELETE http://localhost:8080/user/undefined 400

这前端使用vue实现增删改查的时候,在进行根据id进行删除的时候出现了一个问题

报错

在这里插入图片描述

DELETE http://localhost:8080/user/undefined 400

原因

undefined他是不明确的意思,说明我们这个post请求这个链接他不知道你是什么意思。

后端

 //根据id 删除用户信息
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return userService.removeById(id);
    }

解决

我是根据id来删除用户信息的,我的用户id是userid,没有进行@TableName(value =“ID”)操作,在前端的时候使用了id这个参数,所以他就没有找到我们数据中的这个字段名,进而出现了这个错误。更正就解决了。

下面分享几种vue 删除的常用方法

一、根据id删除数据

<!-- 点击传入当前点击的数据 -->
<el-button type="dangerous" @click="handleClickDelProduct(scope.row)">删除</el-button>
 handleClickDelProduct(row) {
        let index = this.newList.findIndex((product) => {
          return row.id == product.id
        })
        if (index !== -1) {
          this.newList.splice(index, 1)
        }
    },

二、根据下标删除对应数据

//index是点击事件传过来的参数下标
<div v-for="(item,index) in list" :key="index">
		<div @click="deletes(index)">
			{{item.name}}
		</div>
	</div>
//拿到当前下标 通过splice方法删除当前下标所在数据
   deletes(index){
		this.list.splice(index, 1)
	 }

三、 通过接口方式删除数据

<el-popconfirm                 
   confirm-button-text='确定'
   cancel-button-text='我再想想吧'
   icon="el-icon-info"
   icon-color="red"
   title="确定删除这一段内容吗?"
   @confirm="handleDelete(scope.row.userid)"
   >
<el-button style="margin-left: 5px" type="danger" slot ="reference" >删除<i class="el-icon-remove"></i></el-button></el-popconfirm>
//删除
    handleDelete(userid){
      request.delete("http://localhost:8080/user/"+userid).then(res => {
        if (res){
          this.$message.success("删除成功")
          this.load()  //load是我封装的
        }else{
          this.$message.error("删除失败")
        }
      })
    },
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值