When using a file uploader to set an image on v-model in Vue JS, it sometimes results in

I am currently using Vue JS 2 to develop an image uploader functionality. The input in question has a change function that triggers a function and sets the selected file to the v-model property.

After logging the data, I noticed that only an empty object is being set instead of the actual image. This issue is also causing the Vee Validate rule to fail as it detects the data as empty.

What could be missing in my implementation?

This is the HTML code snippet for uploading a logo:

<validation-observer ref="brandCreationForm" v-slot="{ handleSubmit }">
  <form class="space-y-6" @submit.stop.prevent="handleSubmit(create)">
    <validation-observer :key="1" class="space-y-6">

      <pre>
        {{ form }}
      </pre>

      <!-- Rest of the HTML code omitted for brevity -->

    </validation-observer>
  </form>
</validation-observer>

A specific function within my script runs as follows:

<script>
export default {
  // Layout and data setup goes here
  methods: {
    // Create brand and upload image functions are defined here
  }
}
</script>

The issue arises when adding an image where the form should ideally contain all information related to the image, but instead shows up as an empty object as depicted in the screenshot below:

https://i.stack.imgur.com/YuIex.png

Attempts such as using JSON.stringify before setting the model have been made, but unfortunately without success.

Answer №1

The formData object contains only functions, making it appear as an empty object when rendered in the template. To display the content of formData in the template, you must call one of its prototype functions and show the results.

<div v-for="item in form.brand_logo.values()">
  {{ item }}
</div>

Check out this codesandbox link to see how selecting a file displays it in the template and console.

If you want to simplify your code like I did with focusing on the formData aspect, consider creating a reproducible example for better understanding.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Backbone collection not being updated despite making a JSONP request

Recently, I delved into the world of Backbone.js and currently, I am immersed in developing an app using Brunch that makes a JSONP request to an external API for populating my collection and models. Despite following guidance from previous posts (here and ...

Managing numerous callbacks for a specific route within Express.js

After going through the Express.js documentation, I came across a section discussing how to handle callbacks for routes using the syntax: app.get(path, callback [, callback ...]) However, I encountered difficulty in finding an example that demonstrates ...

What are some ways to access my AsyncStorage data from any location?

I am utilizing the saga library and storing tokens in AsyncStorage. My goal is to be able to freely access the token retrieved from AsyncStorage in both the loadUserPosts function and the loadPosts function. Where should I add async and how can I correct ...

Await keyword cannot be used due to undefined object reference

Currently in the process of implementing authentication into my node API. Using PassportJS, although I am fairly new to this so please bear with me. The goal is to add a local strategy and verify the user's password during login: // Local Strategy ...

What could be causing this template to malfunction?

Every time I try to start my Express server and access the page, I encounter an error. Can anyone pinpoint what might be wrong with the syntax? The "startzeit" property is a Date() Object. <tbody> <% for (let seminar in seminare){ %> ...

Selecting elements by class in jQuery using a variable for the class name

Is there a way in jQuery to apply actions to all elements with a specific class, where the class name is determined by a variable? I want to select elements based on this dynamically generated class name. var x = $(this).attr('href').slice(1); ...

Activate click events when button is being held down

I'm currently working on a directive that shifts an element to the right whenever clicked. However, I want the element to keep moving as long as the button is pressed. .directive("car", function(){ return { restrict:"A", link:func ...

Clicking on a checkbox within an HTML table that incorporates handlebar and Express.js

My situation involves a HTML table within a form that is being populated with Handlebars. I need to be able to select certain rows in the table using checkboxes, and upon form submission through a POST request in an Express.js framework, I require the JSON ...

The ajax request functions smoothly on the OS X Paw app and cURL, but does not work properly when coded in Javascript / jQuery

Currently delving into the world of ajax requests, I've been utilizing the Paw app to troubleshoot one. Surprisingly, the request functions flawlessly within Paw itself and even the cURL code generated by Paw works like a charm. However, the JavaScrip ...

What are the methods for differentiating between a deliberate user click and a click triggered by JavaScript?

Social media platforms like Facebook and Twitter offer buttons such as Like and Follow to allow users to easily engage with content. For example, on Mashable.com, there is a Follow button that, when clicked, automatically makes the user follow Mashable&ap ...

How to implement a feature for uploading multiple files through a single form with unique input fields in a web

After searching on Stack Overflow, I couldn't find a suitable solution for my problem. I need help with my code that fetches data and sends it to a PHP file to upload files to specific folders and store their links in a database. However, I am encount ...

bespoke theme background hue

I currently have material-ui@next installed and I am attempting to customize the background color of the theme. Here is what I have tried: const customizedTheme = createMuiTheme({ palette: createPalette({ type: 'light', primary: purple ...

What are some strategies to enhance the efficiency of this code and reduce repetition?

Here's an overview of the component in question export default () => { const { currentUser, logout } = useAuth(); const [sideBarOpen, setSideBarOpen] = useState(false); const theme = useTheme(); const classes = useStyles(); const isSmall ...

How can I transform each word to resemble this format?

let sentence = "Hello+world + like+ this + name,bla"; sentence = sentence.replace(/\+\s\+/g, function(match){ return "*" + match.trim() + "*"; }); alert(sentence); // Output will be " *Hello*+*world*+like*+this*+name,*bla* "; How can I ...

Retrieve posts based on categories using the WordPress REST API and Vue.js

I'm currently attempting to retrieve post data using the Wordpress Restful API. My progress so far includes: Upon loading the app, fetching the initial page of posts. If the user clicks the 'load more posts' button, another page of posts i ...

Having trouble with Angular UI Select functionality?

I have integrated the angular ui select library from https://github.com/angular-ui/ui-select into my project. Instead of using the traditional select element, I am now utilizing the ui-select directive. This is a snippet of my code: <select class=" ...

Participating in a scheduled Discord Voice chat session

Currently, I am in the process of developing a bot that is designed to automatically join a voice chat at midnight and play a specific song. I have experimented with the following code snippet: // To make use of the discord.js module const Discord = requ ...

Determine if the start_date is greater than the end_date using jQuery

Having a particular issue with date validation. The start_date and end_date are obtained from an HTML form, being chosen using a bootstrap date picker. A sample of the dates looks like this: start_date = 15-06-2016 end_date = 14-06-2016 To verify if th ...

How to extract and display data when clicking on a Bootstrap switch

I have integrated BootStrap Switch like this: <?php while ($arr = mysql_fetch_array($res)) { ?> <td class="center"> <?php if ($arr['status'] == 1) { ?> <input class="switch" type="checkbo ...

TimeStamp Recorder - Typescript

I'm trying to create a timer that counts the time when a button is pressed. Currently, I have managed to display the minutes and seconds on the screen as soon as the button is clicked. For example: 21(min):02(sec) What I am struggling with is updati ...