I have this model files where I have a property that is response that inside has an array errorMessages and inside my Vue component I want to show errors one by one, not in array format.
Is there any way to do it?
    {
  "files": [
    {
      "fileObject": true,
      "size": 9387,
      "name": "file_4444.pdf",
      "type": "application/pdf",
      "active": false,
      "error": true,
      "success": true,
      "postAction": "http://localhost:8000/api/v1/car/upload",
      "timeout": 0,
      "file": {},
      "el": {
        "__vue__": null
      },
      "response": {
        "uploadDone": 0,
        "uploadFail": 1,
        "errorMessages": [
          "User not found",
          "Car not found",
        ]
      },
      "progress": "100.00",
      "speed": 9591,
      "data": {},
      "headers": {},
      "id": "096vnj6rov9t",
      "xhr": {}
    }
  ]
}
<template>
  <div class="example-drag">
    <div class="upload">
      <ul v-if="files.length">
        <li v-for="(file, index) in files" :key="file.id">
          <span>{{file.name}}</span> -
          <span v-if="file.error"> {{ file.response.errorMessages }} <md-icon>thumb_down</md-icon> </span>
          <span v-else-if="file.success">success <md-icon>thumb_up</md-icon> </span>
          <span v-else-if="file.active">active <md-icon>thumb_up</md-icon> </span>
          <span v-else>  ... </span>
        </li>
      </ul>
   ...
</template>
you need to iterate over the errorMessages array
<ul v-if="files.length">
  <li v-for="(file, index) in files" :key="file.id">
    <span>{{file.name}}</span> -
    <span v-if="file.error"> 
      <ol>
       <li v-for="err in file.response.errorMessages> {{ err }} </li>
      </ol>
    </span>
  </li>
</ul>
Or use the .join method of the array ( ['hola', 'mundo'].join(", ") => 'hola, mundo')
<span v-if="file.error">{{ file.response.errorMessages.join(", ") }}</span>
                            {
  "files": [
    {
      "fileObject": true,
      "size": 9387,
      "name": "file_4444.pdf",
      "type": "application/pdf",
      "active": false,
      "error": true,
      "success": true,
      "postAction": "http://localhost:8000/api/v1/car/upload",
      "timeout": 0,
      "file": {},
      "el": {
        "__vue__": null
      },
      "response": {
        "uploadDone": 0,
        "uploadFail": 1,
        "errorMessages": [
          "User not found",
          "Car not found",
        ]
      },
      "progress": "100.00",
      "speed": 9591,
      "data": {},
      "headers": {},
      "id": "096vnj6rov9t",
      "xhr": {}
    }
  ]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With