The VueJs input file @change event only triggers once in Chrome after the first call

Here is the code snippet I am currently working with:

HTML:

<input id="task-message-input-upload" type="file" ref="file" @change="handleFileUpload($event)" />

Javascript :

data() {
        return {
            uploadedFiles: [],
            showPercentage: false,
            uploadPercentage: 0,
            file: {},
        }
    },
    methods: {
        handleFileUpload(event) {
            this.file = event.target.files[0];
            this.submitFile();
        },
        submitFile() {
            $vm = this;
            this.showPercentage = true;
            let formDataF = new FormData();
            formDataF.append('file', this.file);
            axios.post('/api/v1/savemessagefile',
                    formDataF, {
                        headers: {
                            'Content-Type': 'multipart/form-data'
                        },
                        onUploadProgress: function(progressEvent) {
                                this.uploadPercentage = parseInt(Math.round((progressEvent.loaded * 100) / progressEvent.total));
                            }
                            .bind(this)
                    }
                ).then(function(response) {
                    $vm.uploadPercentage = 0;
                    $vm.uploadedFiles.push(response.data);
                })
                .catch(function() {
                    const Toast = Swal.mixin({
                        toast: true,
                        position: 'top-end',
                        showConfirmButton: false,
                        timer: 3000
                    });
                    Toast.fire({
                        type: 'warning',
                        title: '<%=i18n.__('upload_has_been_canceled ')%>'
                    })
                });
        },
    }

An issue I am encountering is that after processing the file for the first time by clicking the button, it works fine. However, when I try to do the same action again for a second time, the file property remains empty in Chrome, while it works correctly in Firefox.

For reference, here is a gif image demonstrating the problem: https://i.stack.imgur.com/enbPv.gif

Answer №1

Reset the uploadedFiles array to empty after clicking the submit button.

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

How to Use AJAX, jQuery, and JSON to Send an Array to PHP

I'm attempting to send an associative array through AJAX $.post to a PHP script. Below is the code I am using: var request = { action: "add", requestor: req_id, ... } var reqDetails = $("#request_details").val(); ...

AngularJS Interceptors for secure page management

I recently started working with AngularJS and I'm facing an issue with my interceptor that catches 401 errors from server responses. When a 401 status is detected, it triggers a "loginRequired" message broadcast and redirects to the login page. Howev ...

I'm having trouble getting jquery css to function properly in my situation

I am trying to implement a fallback for the use of calc() in my CSS using jQuery CSS: width: calc(100% - 90px); However, when I tried running the code below, it seems like the second css() function is not executing. I suspect that there might be an issu ...

Leveraging React's UseEffect() to retrieve information from GraphQL

I am currently attempting to retrieve data from graphQL. I understand that by placing a function inside the react UseEffect(), I can trigger the function once the data is updated and structured. However, while working on a chatroom feature, I am facing an ...

Change in ReactJS URLs without causing the entire page to refresh when using BrowserRouter

After conducting extensive research and struggling for a solution for quite some time, it appears that I am facing an issue with my ReactJS project. As a beginner in ReactJS, I have developed a game (a quiz) with multiple levels where the component remains ...

Syntax error is not caught - why are there invalid regular expression flags being used?

I'm attempting to dynamically create rows that, when clicked, load a view for the associated row. Check out my javascript and jquery code below: var newRow = $('<tr />'); var url = '@Url.Action("Get", "myController", new ...

Having trouble with npm installation of vue-cli

After updating npm to the latest version, I attempted to install vue-cli using the command: npm install --global vue-cli However, I encountered some issues as indicated below: npm ERR! code EPROTO npm ERR! errno EPROTO npm ERR! request to http://reg ...

waiting for deferred to complete in esri javascript api before continuing with code execution - labelPoints

I'm encountering an issue with obtaining my labelPoints before completing the rest of my code. It seems to be related to a deferred/callback problem that I can't quite grasp, and I couldn't find many examples using the esri javascript api. ...

Locate the closest Vue parent component containing the template reference (Vue 3)

After a Vue template ref is initialized, my goal is to identify the closest parent Vue component. To make this functionality versatile and applicable to any template ref, I have encapsulated it within a composition function (although that's merely an ...

Creating a personalized mouse cursor using HTML

I am trying to set an image as my cursor inside a div container but I want it to disappear and revert back to a normal pointer cursor when the mouse hovers over any link within that div. Here is my code snippet: var $box = $(".box"); var $myCursor = $ ...

Adding content to the parent element immediately after it is generated using jQuery

Is there a way to trigger $(e).append() as soon as the element e is created without using setTimeout()? I find that method inefficient. Are there any DOM events that can detect changes in a subtree of a DOM element? Usually, I would just add the code to t ...

Trouble executing Vue.js project due to an empty jsconfig.json file?

Currently, I am venturing into a Vue.js project. My workspace is VS Code operating as an administrator. The guide I am following can be found at: https://vuejs.org/guide/quick-start.html#creating-a-vue-application My Node version stands at 6.14.13. Verify ...

Establishing headers in hapi.js

Seeking guidance on setting up custom variables for individual routes in hapi.js. How can I configure these variables to be accessible on 'onPreHandler'? Additionally, looking for a way to include headers right before calling reply.continue. Any ...

Could the issue be related to a bug in the combination of ng-repeat and ngInclude?

I've been experimenting with loading different templates in this manner: <div ng-class="{active:$first,in:$first,'tab-pane':true}" id="{{p.path}}_settings" ng-repeat="p in panes" ng-include="buildPath(p.path)"> </div> Here&apos ...

The Laravel 8/Passport/GuzzleHttp API request successfully returns a status code of 200, however, there is no response

Currently, I am in the process of setting up a login page using Vue.js (front-end) with Laravel 8 (back-end), incorporating Passport and GuzzleHttp. The oAuth/Token functionality has been successfully tested using Insomnia. Additionally, the userData retr ...

Retrieve custom content from a database using Laravel and Ajax when clicking on a navigation bar

Recently, I've started working with Laravel 7 and AJAX. One of the features I want to implement is a 'product's name' navbar that displays product details in a div without refreshing the page when clicked. I came across a demo showcasin ...

Webpack is failing to load the logo PNG image file

Is there a way to make the logo png file visible on the webpage? I have been encountering issues with loading the image while other elements like HTML, css, and fonts are loading properly when the web pack is started. List of Error Messages: Refused to a ...

Incorporating the ThreeJS Transform tool into the Autodesk Forge Viewer

Trying to implement ThreeJS Transform control into the Forge Viewer by following an informative tutorial: The current issue is being able to add the Transform Control successfully, but not being able to interact with it. I had to make a slight adjustment ...

What are the reasons for being unable to access the HTML canvas in Vue?

I am currently working on creating a canvas element in Vue, but I seem to be encountering issues with the canvas instance. It appears that I may not be declaring or utilizing it correctly, as I am receiving the following error: TypeError: Cannot set pro ...

Trouble with the query waypoints extension in a simple demonstration

Can anyone help me figure out why the basic example from the waypoints plugin isn't working for me? Here's a link to the jsfiddle I created: http://jsfiddle.net/ZA8bd/2/ CSS .block1 { margin-top:30px; width: 400px; background: red; ...