What is the correct method for accessing $event in VueJS on Firefox after clicking an element?

Utilizing VueJS 2.3.0 to update images and other details when a user clicks on the menu.

The menu is dynamically created using JSON data with a VueJS template:

<template id=\"rac-menu\">
    <ul class=\"col-md-3\" v-show=\"!ajanlatkeres\">
        <li v-for=\"model in models\" model=\"model\">
            <a href=\"javascript:;\"
               class=\"rac_setactive\"
               v-on:click=\"setActive(\$event)\"
               :data-id=\"model.id\">
                   {{ model.name }}
             </a>
        </li>
    </ul>
</template>

Below is the VueJS script code:

Vue.component('racmenu', {
    template: '#rac-menu',
    data: function() {
        var models = {};
        for (var id in rac_data ) {
            models[id] = {};
            models[ id ]['id'] = id;
            models[ id ]['name'] = rac_data[id].modell;
        }
        return {models: models};
    },
    props: ['model','ajanlatkeres'],
    methods: {
        setActive: function(e) {
            bus.\$emit('set-rac-content', e.path[0].dataset.id);
        },
    }
});

Everything works fine in Chrome, but I encounter an error in Safari and Firefox: TypeError: e.path is undefined.

What can be done to resolve this issue?

Answer №1

In the realm of web browsers, e.path is an attribute exclusive to Chrome. You can attempt substituting e.path[0] with e.target

If that solution proves unfruitful, you can try utilizing composedPath. Refer to this inquiry for guidance

Answer №2

To activate in HTML, only call setActive instead of setActive($event) which is the default:

<a href=\"javascript:;\"
   class=\"rac_setactive\"
   v-on:click=\"setActive\"
   :data-id=\"model.id\">
   {{ model.name }}
</a>

Within the function, use the following code:

setActive: function(e) {
   bus.\$emit('set-rac-content', e.target.path[0].dataset.id);
}

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

Error in refreshing JWPlayer page: Plugin loading failure - File not located

I'm implementing JWPlayer on my Localhost environment. Here's the code snippet I'm using: <div id="Player">loading...</div> <script type="text/javascript"> jwplayer("Player").setup({ file: "<?php echo $video[' ...

Enhance the efficiency of AngularJS search filtering

With nearly 2000 rows on this page, I am using AngularJS filter to search for items containing the typed strings. However, I have noticed that the efficiency is poor when typing just one character into the input control. Does anyone have suggestions for im ...

Printing content to an HTML page using Node.js

I'm seeking advice on using Node JS, AJAX, and other related technologies. My goal is to display the content of a JSON file on my HTML page. While I've been successful in saving new objects to the JSON file, I'm struggling to find an effecti ...

Step-by-step Guide on Installing VueJs Medium Editor

After spending countless hours trying to install Medium Editor in VueJs, I finally got it working on a single page vuejs. However, I hit a roadblock when trying to make it work with the webpack file structure: ├── main.js # app en ...

When using Vue and Axios to make a GET request to the YouTube search API, I received a 404 error

Having some trouble with my code. I'm attempting to send a get request to the YouTube API using a specific keyword, but the query string is returning a 404 error even though I've included referring URLs and have a valid API key. The method where ...

In order to populate an image carousel container in Angular with an object array, I plan to dynamically allocate the array using a loop within the component class

My concern lies in what seems to be a misuse of the image carousel HTML code structure. Here is my HTML: <div id="carousel-trades" class="carousel slide carousel-fade" data-ride="carousel"> <div class="carousel-inner" role="listbox"> < ...

JavaScript: Retrieving the names of children within a <div> element

Within my structure setup, there is a tower div with inner elements like this: <div class="tower"> <div class="E0">abc</div> <div class="GU">123</di </div> The challenge I am facing is that I need to access the in ...

Where should constants be kept in Nuxt.js?

What is the ideal location for storing constants? I want to save key-value pairs to quickly swap IDs with corresponding names. For example: const roleNames = { 1: 'Admin', 2: 'Moderator' 3: 'User' } Would using vuex ...

How to Develop a WebSocket Client for Mocha Testing in a Sails.js Application?

I've been attempting to utilize the socket.io-client within the Mocha tests of my Sails JS application for making calls like the one shown below. However, the .get/.post methods are not being invoked and causing the test case to time out. var io = re ...

Strange problem encountered while using npm

Hello, I am encountering an issue where I run the command: npm run watch and it provides the following output: /public/js/app.js 1.94 MiB /public/js/app [emitted] /public/js/app // large list of files and sizes /// public/css/app.css 193 ...

Utilizing arrays for generating tables in React

I needed to design a table using data retrieved from an API, where only specific columns should be visible by default. Here are two arrays, one containing the default column headers for the table and the other containing the id and title of the data: const ...

Having trouble getting NextJS to work with jsmpeg/node-rtsp-stream for displaying an RTSP stream

Exploring: https://github.com/kyriesent/node-rtsp-stream and How to display IP camera feed from an RTSP url onto reactjs app page? I attempted to showcase the RTSP stream from a CCTV but encountered an error. ReferenceError: document is not defined at scri ...

Vue component with a variable number of rows, each containing a variable number of input fields

I am currently working on creating a form that can have a variable number of steps. Users should be able to add an additional step by clicking a button. Each step will contain some input fields and buttons to dynamically create more input fields. For inst ...

Show targeted information from the array using the respective identifier

Is it feasible to exhibit data from a Vuex store array in a unique manner, comparable to the illustration provided below: <template> <div> <h1>{{this.$store.state.data.title}}</h1> <p>{{this.$store.state.da ...

Removing entered text from a Vuetify V-autocomplete once a selection has been made from the dropdown menu

One issue I'm encountering involves a v-autocomplete field with a drop-down list of items. It allows for multiple selections. <v-autocomplete v-model="defendantCode" label="Defendant Code" :items="defendantCodeOptions" ...

What steps should be taken to fix the sinopia installation error?

While operating on redhat5.9, I encountered an exception related to 'make'. I am curious about what they are trying to create. It seems like it's related to JavaScript. [root@xxxx bin]# npm install -g sinopia --python=/usr/local/clo/ven/pyt ...

As the user types input in real time, automatically adjust the form's value before submission

I'm looking for assistance in dynamically updating the value of a form submit button as the user types into an input field. <form> <input type="text" name="number" id="number" value = 0 /> <input type="submit" id="submit"> ...

Exclude crypto-browserify from the NextJS build process

I have been dedicated to minimizing the build size of my app as much as possible, and I have observed that the crypto-browserify module is consuming a significant amount of space. While I understand that Next.js polyfills the node module if necessary, I wo ...

Using React and Redux: Sending a function to a child component, triggering it without a handler in the child component

I am experiencing difficulty sending an action through a callback in the code provided below. The action is not being sent as expected. However, if I add the Connected property to a handler like onClick, then the action is executed. How can I make my code ...

What are some ways to render a React component when its ID is only determined after making an AJAX call?

Currently, I am working on developing a chat application where a chat message is immediately displayed (using a React component) once the user sends it by hitting the Enter key: https://i.sstatic.net/MJXLd.png https://i.sstatic.net/S6thO.png As shown in ...