I am having trouble checking the response values of a `Vue` API request. I attempted to use `resp.data == "-1"`, but it is not yielding the desired outcome. Can someone assist me in determining how to properly check the response value in `Vue.js`?
Vue.js function:
callback: function () {
this.$http
.post(`/api/food-item/${data.ItemId}/delete`)
.then((resp) => {
if(resp.data == "-1")
{
ShowError(this.$toast, "Used Items!!");
}
else
{
ShowSuccess(this.$toast, "Food item deleted successfully");
resp.data;
self.$nextTick(function () {
self.$refs.vuetable.refresh();
});
}
})
.catch((error) => {
const errorMsg = error.response.data.ExceptionMessage;
ShowError(this.$toast, errorMsg);
});
},
C# code:
[Route("{foodItemId}/delete")]
[HttpPost]
public IHttpActionResult Delete(int foodItemId)
{
if (!foodItemService.IsExist(foodItemId))
{
return NotFound();
}
if (foodItemService.IsUsed(foodItemId))
{
return Ok("-1"); //this line is the return line
}
foodItemService.Delete(foodItemId);
return Ok();
}
Error encountered in the terminal:
312:19 error Replace `(resp.data·==·"-1")␍⏎···············` with `·(resp.data·==·"-1")` prettier/prettier
315:18 error Replace `␍⏎················else␍⏎···············` with `·else` prettier/prettier
323:18 error Delete `␍⏎················` prettier/prettier