4

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>

2 Answers 2

5

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanxs , this is just I need it.
1

    {
  "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": {}
    }
  ]
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.