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

What is the best way to save Vue state in a cookie while transitioning between form steps in a Laravel application

Imagine a scenario where a user is filling out a multi-step form, and we want to ensure that their progress is saved in case they lose connection. This way, the user's data will not be lost between different form steps. In addition to saving each ste ...

Setting the default <a-sky> in Aframe: A step-by-step guide

There was a fascinating projection I witnessed where two images were displayed in the sky. [https://codepen.io/captDaylight/full/PNaVmR/][code] Upon opening it, you are greeted with two spheres and a default white background. As you move your cursor over ...

Ways to alter and remove ArrayList arrangement

I am new, so please excuse all the questions. Could you kindly explain to me? <ul id="example-1"> <li v-for="item in items"> {{ item.message }} <v-btn>up</v-btn> <v-btn>down</v-btn> ...

Displaying a list of objects in Vue.js using an <a> tag to iterate

I am attempting to loop through a list of objects and display their attributes in the <a> tag For instance: <a href="link.url" target="_blank"><i class="links.fontawsomeicon" alt="link.text"></i ...

NextJS 13 causes tailwind to malfunction when route group is utilized

I've encountered an issue in my NextJS 13 application where Tailwind classes are no longer being applied after moving page.tsx/layout.tsx from the root directory to a (main) directory within the root. I suspect that there may be a configuration that i ...

vm.property compared to this.property

Although it may seem like a simple question, I am in need of some clarification. Currently, I have vuejs running on a single page of my website. The vm app is running in the footer script of the page without utilizing an app.js file or templates/components ...

Javascript regular expression fails to find a match

Is there a way to match all strings except for the ones containing '1AB'? I attempted it but it returned no matches. var text = "match1ABmatch match2ABmatch match3ABmatch"; var matches = text.match(/match(?!1AB)match/g); console.log(matches[0]+" ...

Tips on utilizing controllers within AngularJs directives?

In order to utilize a controller in my directive, what is the best way to access all controller functions within the directive? directive.js angular.module('App').directive('deleteButtons', function (prcDeleteFactory,$rootScope) { & ...

I am seeking assistance to utilize Flexbox to completely fill the height of my computer screen

Seeking assistance in utilizing Flexbox to occupy 100% of my computer screen's height, all while ensuring responsiveness: View of my current sign-in page on Chrome (Note the whitespace): Examining my existing frontend code: const SignIn = () => { ...

Determine the minimum and maximum width of jQuery UI resizable during the "resizestart" event

As a newcomer to Javascript, I am facing challenges navigating my way around. Currently, I am attempting to create a jQuery plugin that will facilitate resizing elements using the jQuery UI resizable plugin. My goal is to implement logic that dynamically ...

AngularJS: How to accurately retrieve the offsetTop value upon page initialization

Issue: I am facing difficulty in obtaining the accurate top offset value of a DOM element immediately after the page has loaded. In the project I am currently working on, it is essential to retrieve the offsetTop value of various DOM elements as soon as ...

javascript if an error occurs, refresh the webpage

Currently, I am inquiring about the most effective method for managing JavaScript errors. Given that my application relies heavily on JavaScript, despite diligent testing efforts, encountering bugs is almost certain. I'm interested in knowing if ther ...

A step-by-step guide on configuring data for aria's autocomplete feature

Currently, I am implementing aria autocomplete and facing an issue while trying to populate data from the server into the selection of aria autocomplete. I have tried setting the selected property of the aria autocomplete object, but it doesn't seem t ...

Attempting to capture a previously unhandled error thrown by Axios when utilized in conjunction with React Query (with suspense mode enabled) within a NextJs application

Utilizing NextJS, React query (with axios and suspense mode), I am attempting to handle an intentional 404 error from my API. Although I successfully caught it in my error.js file, the same error still shows up in the console as "uncaught." https://i.stack ...

Is it possible to transfer a JSON object from Silverlight to JavaScript?

Is it possible to pass a JSON object directly from Silverlight to JavaScript, or does it have to be serialized first? ...

Thumbnail Option in the WordPress Media Uploader

Is it possible to add support for selecting image size (thumbnails) in the Media Library popup created using the wp.media() function in WordPress? I am currently using WordPress 4.5.2 and my code sample is as follows: wp.media.frames.selectFile=wp.media( ...

Encountering an error with the node module timestampnotes: 'command not recognized'

I am encountering an issue while trying to utilize a npm package called timestamp notes. After executing the following commands: $npm install timestampnotes $timestamp I receive the error message: timestamp:126: command not found: slk Subsequently, I ...

Is there a solution to the Chrome issue "Require user interaction for beforeunload dialogs" that arises while running Cypress tests?

Require user gesture for beforeunload dialogs A new feature has been implemented where the beforeunload dialog will only be displayed if the frame attempting to show it has received a user gesture or interaction, or if any embedded frame has received su ...

Receiving feedback from an Ajax request

When attempting to retrieve the responseText from an AJAX call created in plain JavaScript, there seems to be an issue where Firebug can detect the request but cannot obtain a reference to the responseText. Below is the code for the function: function ge ...

Guide on mocking a function inside another function imported from a module with TypeScript and Jest

I have a function inside the action directory that I want to test: import { Action, ActionProgress, ActionStatus, MagicLinkProgress } from '../../interfaces' import { areSameActions } from '../actionsProgress' export const findActionPr ...