So I got this if statement that checks whether media file is type of image. Whether is true, how can I exit this if statement and continue to next lines of codes where is await... ?
When I added : continue I am getting error expression expected.
if(mediaValue.value == 'image') {
const validateMedia = mediaFile.value.files[0].type.indexOf("image/") > -1
return validateMedia == false ? showToast("notImageFile", "error") : continue;
}
await createData(
route.params.shopid,
route.params.id,
params
);
You don't return from an if. If you want it not to show the toast popup in a certain situation then simply add another if so the code will skip that command when the condition isn't met. For example
if (validateMedia == false) showToast("notImageFile", "error");
After that the code will exit the if block naturally and continue with the next command.
P.S. If you want the processing to pause when the toast popup shows that's a slightly separate question...
Don't return in the if statement. That'll solve your problem. When you return, you return from the function and no more execution ( The async call) will happen.
shouldn't this normally work?
if(mediaValue.value == 'image') {
const validateMedia = mediaFile.value.files[0].type.indexOf("image/") > -1
// if validate media is false then it will return, if not then it will not return
if( validateMedia == false)
showToast("notImageFile", "error");
}
await createData(
route.params.shopid,
route.params.id,
params
);