Component fails to trigger @click handler

.vue component

<template>

<div class="modal">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                Loading Files
            </div>

            <div class="modal-body">
                <input type='file' multiple='multiple' class='form-control' @change='changed'>

                <div v-for='file in files'>
                    {{ file.name }} {{ formatSize(file.size) }}
                </div>
                <div class='alert alert-danger' v-if='error.files' v-for='err in error.files'>
                    {{ err }}
                </div>
                <div class='alert alert-danger' v-if='failed.length' v-for='f in failed'>
                    Failed to upload: {{ f }}
                </div>
                <template v-if='saved.length' v-for='f, index in saved'>
                    <div class='alert alert-info'>
                        {{ f.original_filename }}
                        <a href='#' class='badge badge-info pull-right' @click.native='delete(f, index)' title='Delete'>
                            <i class="fa fa-spinner fa-pulse fa-1x" v-if='f.isDeleting'></i>
                            <i class='fa fa-close' v-else></i>
                        </a>
                    </div>
                    <div class='alert alert-danger' v-if='f.isError'>
                        {{ f.isError }}
                    </div>
                </template>
            </div>

            <div class="modal-footer">
                <button type='button' class='btn btn-default' @click='handleOk' v-if='saved.length && !isUploading'>
                    OK
                </button>
                <button type="button" class="btn btn-default" @click="handleUpload">
                    <template v-if='isUploading'>
                        <i class="fa fa-spinner fa-pulse fa-1x"></i>
                    </template>
                    <template v-else>
                        Upload
                    </template>
                </button>
                <button type="button" class="btn btn-default" @click="handleCancel">Cancel</button>
            </div>

        </div>
    </div>
</div>

</template>
<script>
export default {

    props: {
        propShow: {
            required: true,
            type: Boolean
        }
    },

    data() {
        return {
            files: [],
            saved: [],
            failed: [],
            isUploading: false,
            modal: null,
            input: null,
            error: {},
        }
    },

    watch: {
        propShow: function(val, oldVal) {
            if(val) {
                this.modal.show('modal');
            } else {
                this.modal.hide('modal');
            }
        }
    },

    mounted() {
        this.modal = $(this.$el);
        this.input = this.modal.find('input[type=file]');
    },

    methods: {
        changed(e) {
            let files = e.target.files || e.dataTransfer.files;
            this.files = files;
        },

        delete(f, index) {
            f.isDeleting = true;
            delete f.isError;
            this.$set(this.saved, index, f);
            this.doPostRequest('/file/' + f.id + '/delete', {}, (body) => {
                f.isDeleting = false;
                if(body.ok) {
                    for(let i = 0; i < this.saved.length; i++) {
                        if( this.saved[i].id === f.id ) {
                            this.saved.splice(i, 1);
                        }
                    }
                } else {
                    f.isError = body.data.error;
                    this.$set(this.saved, index, f);
                }
            }, (body) => {
                f.isDeleting = false;
            });
        },

        handleOk() {
            if( this.isUploading ) return;
            this.$emit('ok', this.saved);
            this.saved = [];
            this.failed = [];
        },

        handleUpload() {
            if( this.isUploading ) return;
            this.isUploading = true;
            let data = new FormData();
            for(let i = 0; i < this.files.length; i++) {
                data.append('files[]', this.files[i]);
            }
            this.error = {};
            this.doPostRequest('/file/upload', data, (body) => {
                if(body.ok) {
                    this.saved.push.apply(this.saved, body.data.saved);
                    this.failed.push.apply(this.failed, body.data.failed);
                    this.files = [];
                    this.input.val('');
                } else {
                    this.error = body.data;
                }
                this.isUploading = false;
            }, (body) => {
                this.isUploading = false;
            });
        },

        handleCancel() {
            if( this.isUploading ) return;
            this.files = [];
            this.input.val('');
            this.failed = [];
            for(let i = 0; i < this.saved.length; i++) {
                this.delete(this.saved[i], i);
            }
            this.saved = [];
            this.$emit('cancel');
        },

        formatSize(size) {
            if (size > 1024 * 1024 * 1024 * 1024) {
                return (size / 1024 / 1024 / 1024 / 1024).toFixed(2) + ' TB';
            } else if (size > 1024 * 1024 * 1024) {
                return (size / 1024 / 1024 / 1024).toFixed(2) + ' GB';
            } else if (size > 1024 * 1024) {
                return (size / 1024 / 1024).toFixed(2) + ' MB';
            } else if (size > 1024) {
                return (size / 1024).toFixed(2) + ' KB';
            }
            return size.toString() + ' B';
        }
    }

}

When I click on '.fa-close' link (this part below) - it should trigger the delete method, but it does not.

                    <div class='alert alert-info'>
                    {{ f.original_filename }}
                    <a href='#' class='badge badge-info pull-right' @click.native='delete(f, index)' title='Delete'>
                        <i class="fa fa-spinner fa-pulse fa-1x" v-if='f.isDeleting'></i>
                        <i class='fa fa-close' v-else></i>
                    </a>
                </div>

In Chrome developer tools, I can see that the event handler is attached to this link.

Answer №1

The issue was that my function was named after a reserved word in JavaScript - 'delete'

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

The data displayed in the <span> element isn't reflecting the response from the loaded page, despite being visible in Firebug

I have encountered a problem while trying to load a signup.php page into a div on my main page. All the elements (forms, JavaScript, etc.) function correctly in the loaded page, except for one issue - I cannot get the response from the PHP script to displa ...

Encountering Issues with Importing vue-router in Vue.js 3 - What Could be the Problem?

Here are the files I am working with: router.js import VueRouter from 'vue-router' export const router = VueRouter({ routes: [ { ... } ] }) main.js import { createApp } from 'vue' import App from './App.vue ...

Enhance the efficiency of your JavaScript code by minimizing repeated selectors

I've been working on a JavaScript project where I came across the following lines of code: $('#content').on('click', 'input[type=submit]', function(){ $('#content').on('click', 'a.removebutton&a ...

"Troubleshooting Error: When accessing a property in AngularJS,

My goal is to retrieve a date value. However, I encounter an error message saying 'Cannot read property 'NTLI' of undefined' whenever the checkbox is unchecked and the date picker is invisible. Strangely enough, everything works fine wh ...

What could be the reason for my dynamic image not appearing in a child component when using server-side rendering in Nuxt and Quasar

Currently, I am tackling SSR projects using Nuxt and Quasar. However, I encountered an issue when trying to display a dynamic image in a child component as the image is not being shown. The snippet of my code in question is as follows: function getUrl (im ...

What is the best way to traverse through a nested JSON file with d3.js?

Greetings. I am currently facing a challenge in navigating through a nested JSON file. Below is the JSON data that I need assistance with: {"Id":466,"Name":"korea", "Occurrences": ...

Using Typescript to remove an element from an array inside another array

I've encountered an issue while trying to remove a specific item from a nested array of items within another array. Below is the code snippet: removeFromOldFeatureGroup() { for( let i= this.featureGroups.length-1; i>=0; i--) { if( this.featureGr ...

Is there a way to merge all this data into a single Object?

This particular situation is quite complex. Let's consider the following scenario: I have two JavaScript objects that are fetched via REST calls, using two different callbacks. So, we have: call1() - POST method - parsed JSON to JavaScript object, ...

Displaying and hiding the top menu when the div is scrolled

I have developed a script that is designed to display the menu in a shaking motion and hide it as you scroll down. It functions properly when scrolling within the body of the webpage, but I am facing issues when attempting to do so with a div that has an o ...

Switch the appearance between two elements

In my HTML table, I have different levels of content - from main "contents" to nested "sub-contents" and even deeper "sub-sub-content". My goal is to hide all sub-content within the content cell that I click on. <table> <tr class=' ...

listening for events on nested classes

I am looking to dynamically toggle the class "collapsed" on each element with the class "category" when it is clicked. The issue arises when these "category" elements are nested within each other, causing the child elements to also trigger the class change ...

Having trouble retrieving user login information in Postman

I have encountered an issue while creating a REST API using Node js and expressJs. When attempting to create a user, I successfully implemented the following code: /** * save user data from the user model */ router.post("/users", async (req, res) => ...

Creating artwork: How to resize images without losing clarity

Struggling to display an image in a canvas element that needs to be a certain percentage of its parent container's width. Despite my efforts, the image seems to blur once added to the canvas, which is not the desired effect. I attempted to disable th ...

Issue with Firebase Cloud function not terminating despite receiving a 204 response code

Currently, I am developing a cloud function to manage server operations for a gaming panel. Everything seems to be functioning correctly except that after the request is completed, it fails to trigger the expected "data", "end", or "closed" events which ...

React - Error: Unable to access the 'props' property because it is undefined

I am working on implementing a click event to delete an item from my list, but I keep encountering the error message "TypeError: Cannot read property 'props' of undefined" whenever I click on it. Although I am striving to follow ES6 standards as ...

Issue with Vue.js not forwarding the authentication token to the server

I am having trouble accessing API protected routes because VueJS seems to be failing to send the authentication token to the Node.js server. It was working fine before, but now it suddenly stopped working. The login and storage of the token in the front en ...

What is the process for sending an InMemoryUploadedFile to my S3 storage?

My upload form is quite simple and includes an image as a FileField: def post(request): if request.user.is_authenticated(): form_post = PostForm(request.POST or None, request.FILES or None) if form_post.is_valid(): inst ...

Complete a bootstrap row and begin a new row after every nth div element

I have a grid layout in Bootstrap that I will be filling with blog post thumbnails. <section class="container"> <div class="row thumbs"> <div class="col-sm-3">content</div> <div class="col-sm-3">content</div> ...

How to eliminate looping animations with jQuery

While looping through items, I am encountering an issue where an animation triggers when the loop returns to the first div. I simply need a way to switch between divs without any animations on a set interval. $(document).ready(function () { function s ...

Ways to activate a button action with jQuery even when it is disabled and clicked

Thank you for the responses. To clarify my goal, I want the form button to submit all select field responses for processing through php on the next page. If a user clicks the submit button before selecting an option in each field, it should display "whoa d ...