json-server中使用RESTFUL API如何实现批量删除

在使用vue做后台管理的系统的时候,会有批量删除的操作,但是在找了很多资料之后仍然无法解决,希望得到大家的帮助。

axios({
  method: 'delete',
  url: that.baseURL,
    params: {
      id: [1,2]
    },
  headers: {'Content-Type': 'application/json'},
  responseType: 'json'
}).then(function (response) {
  console.log(response)
}).catch((error) => console.log(error))

当URL设置为thatbaseURL/id时是可以删除数据的,设置params为id:1也是无法删除数据的,会报如下错,是delete不支持设置params吗?
图片描述
附server.js部分配置:

server.use(jsonserver.rewriter({
  '/api/': '/',
  '/api/users': '/users',
  '/api/users/:id': '/users/:id',
  '/api/users\\?id=:id': '/users/:id'
}))

如果大家发现什么错误,或者有什么建议,希望可以予以指点!

阅读 6.3k
1 个回答

/api/users\\?id=:id改成/api/users?id=:id试试

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进