脑袋疼,折腾了个把小时,终于折腾清楚了,如下例所示,selectedIds 是一个字符串数组,axios 传参的时候不需要任何的包装,花括号什么的都不需要
var that = this
var selectedIds = this.selectedRows.map((o) => o.id)
if (selectedIds.length === 0) {
this.$message.error('请选择需要删除的行!')
return
}
this.$confirm('是否确认删除所选择的行?', '删除', {
confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
}).then(() => {
this.axios.post('/Role/DeleteRoles', selectedIds
).then(function (response) {
if (response.data.Success) {
var d = response.data
if (d.Success) {
that.getTableData()
that.getTreeData()
}
}
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消'
})
})
Web Api 这边的接收
[HttpPost]
public IHttpActionResult DeleteRoles(string[] ids)
{
try
{
bool result = _services.DeleteRoles(ids);
if (result)
return Json(new { Success = true });
return Json(new ResponseObj<RoleEntity>
{
Success = false,
Msg = "操作失败!",
ReplyTime = DateTime.Now
});
}
catch (Exception e)
{
return Json(new ResponseObj<RoleVModel>
{
Success = false,
Msg = e.Message,
ReplyTime = DateTime.Now
});
}
}
没什么特别的直接用一个 string[] 接收就好了