Mouse over event functioning, however click event remains inactive

I'm currently working on a project using Vue JS and I've encountered an issue.

Here is the code snippet causing me trouble:

<input v-model="spam" @keyup="spamegg=true;" @blur="spamegg=false;" />
<div v-if="spamegg" class="someclass">
    <a v-for="str in arr" @click.prevent="foobar(); barbaz();" href="#">{{ str }}</a>
</div>

Although I have defined foobar method as:

foobar: function() {
    console.log('clicked');
}

The click event doesn't seem to be triggering. The same issue persists with the barbaz function.

Coincidentally, when I tested it with the @mouseover event, it worked fine.

For reference, the div element behaves like a dropdown in terms of CSS styling.

If you require any additional information, please feel free to ask.

Answer №1

After attempting your example in jsfiddle, I noticed a mistake in the @blur handler where spmaegg was used instead of spamegg. Even after fixing this issue, the click events were still not registering properly. It appears that removing the blur event allows the events to register as intended. This could be due to the timing of the blur event on mousedown conflicting with the click event firing after mouseup, causing the div containing the links to disappear before being fully clicked. Perhaps a new approach is needed for the dropdown functionality, such as implementing a container around the input element and link list to handle the blur event separately, ensuring that clicking within the link list does not trigger the blur effect.

Here is a link to my fiddle without the blur handling, demonstrating proper console output: https://jsfiddle.net/L1khuca2/

Answer №2

When considering implementing a dropdown feature, my suggestion is to hide the div upon clicking a link, while also adding the text value of the link to the input field. Additionally, it would be advisable to remove the @blur event from the code:

new Vue({
  el: '#app',
  data: {
    spam: '',
    spamegg: false,
    arr: ["aaa", "bbb", "ccc"]
  },
  methods: {
    foobar: function(str) {
      console.log('clicked');
      this.spam = str;
      // this.spamegg = false;
    },
    barbaz() {
      console.log('bar');
    }
  }

})
body {
  height: 500px;
  width: 100%;
  display: flex;
  padding: 10px;
  flex-direction: column
}

#app {
  background: #725585;
  height: 100%;
  width: 100%;
  padding: 20px
}

.someclass {
  display: flex;
  flex-direction: column
}

a {}
<head>
  <meta name="description" content="Vue.delete">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.1/vue.min.js"></script>
</head>

<body>
  <div id="app" @click.stop="spamegg = false;">
    <input v-model="spam" @keyup="spamegg=true;" />

    <div v-if="spamegg" class="someclass">
      <a v-for="str in arr" @click.prevent="foobar(str); barbaz();" href="#">{{ str }}</a>
    </div>
  </div>

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

Creating JQuery UI Tabs using dynamically generated DIV elements

I'm currently in the process of developing an information dashboard that will display the outcomes of various actions within a web application. My goal is to present the data in tables, organized by tabs. Each tab will represent a different category ...

Combining AngularJS with ng file upload and Sails JS for seamless file uploading

When I upload a file, I also need to send some additional information along with it. The instructions mention using the data parameter for this purpose, but I'm having trouble accessing it in my Sails controller action. Frontend: Upload.upload({ url ...

I am currently having issues with the mustache syntax in vuejs, as it is not functioning properly

Having an issue with Vue.js where the mustache syntax isn't working properly. <!DOCTYPE html> <html> <head> <title>index</title> <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cg ...

Updating DOM elements in AngularJS based on search results and user clicks

I have a query regarding my angular web app, which includes an ajax call for json-formatted dates to display them in a table. The app features a search input, two sorting buttons (for age or name), and a profile sidebar element. I have successfully update ...

What is the proper way to preload a set of objects in a list or array in NextJS?

I currently have an image displayed on one of my pages using next/image, with the priority set to true in order to eagerly load the asset from the state const [imageToUse, setImageToUse] = useState(initialImage); <Image src={imageToUse} alt='scrol ...

Failure to pass a variable declared within a function to another JavaScript file running simultaneously

After combing through numerous posts on Google and Stack Overflow, I am still unable to pinpoint why this particular issue persists. This case involves 2 HTML files and 2 JS files (explanations provided below in text following the code snippets). 1) inde ...

Leveraging jQuery to extract numerous concealed data from a webpage based on their names

Here is the scenario: <input type="hidden" name="uID" id="uID" value="251|0"> <input type="hidden" name="uID" id="uID" value="252|0"> <input type="hidden" name="uID" id="uID" value="253|0"> <input type="hidden" name="uID" id="uID" val ...

Retrieving user email with Vue.js from Firebase

Currently, I am in the process of developing a chat application using Vue.js and Firebase. This project has been quite challenging for me as I am new to both Vue and Firebase. One specific issue I have encountered is trying to retrieve the user's ema ...

Utilizing the Bing Translation API to translate an entire webpage

I am currently attempting to use the Bing API to translate an entire webpage instead of using the Bing widget. This is because I want to create a custom design for the translation panel, However, I have been unable to find any resources on how to do this ...

Utilize Sass @extend to incorporate imported CSS files in the build process

In my development setup, I have a global CSS file that houses all of the generic CSS styles. My goal is to extend the classes from this global CSS file in any of my SCSS files. However, when I attempt to do so, I encounter an error stating that the .xyz c ...

jQuery scrollTop animates to the start of the webpage

Upon loading the page, the div appears at the top of the screen but then jumps to its correct position once scrolling begins. To view the website, click on this link: calretirement.com/classes-test.php CSS: .register{position:fixed !important; bottom:1 ...

Discover similarities between two arrays

My goal is to compare two arrays and generate a JSON array marking true if there's a match and false if there isn't. The second array will always have values that match some from the first, and it will be smaller as it's derived from the fir ...

Obtaining only a portion of the text when copying and editing it

I have a React application where I am attempting to copy text from an HTML element, modify it, and then send it back to the user. I have been successful in achieving this, but I am facing an issue where even if I select only a portion of the text, I still ...

Activating/Deactivating Drop-down Menus Depending on Selected Options

I'm attempting to control the enable/disable functionality of two select boxes based on the user's selection in a third box using jQuery. The goal is to enable select box 2 when the user chooses one of the first two options in the controller, and ...

Troubleshooting a Recursive Menu Problem in Vue.js

I've been attempting to create a recursive menu in Vue.js, but I keep encountering an error and I'm struggling to identify the issue. Here is my current structure: MenuList.vue <template> <ul class="menu"> <MenuLink v ...

Sudden slowdown due to Jquery error

I am encountering an issue with the Jquery registration validation. I am struggling to display the error message if a name is not filled in. jQuery(document).ready(function () { $('#register').submit(function () { var action = $(thi ...

Having trouble converting svg to png, thinking it might be due to discrepancies in svg elements

I am facing a puzzling issue where two different SVG elements are causing my JavaScript to work in one scenario but not the other. I have replaced the SVG elements in both examples, and surprisingly, only one works while the other does not. You can view th ...

Unable to reach props during mounted lifecycle stage

I am currently working on a Vue component that looks like this: <template> <div> <div class="page-head"> <h4 class="mt-2 mb-2"> {{form.name}} </h4> </div> <f ...

display a container and navigate to the specific link

Greetings! Could someone please help me make this code function properly? I am attempting to display the DIV (slidingDiv) and navigate to the selected ANCHOR (#anchor-01 + #anchor-02 + #anchor-03)... However, the code currently only allows me to go to the ...

A TypeScript example showcasing a nested for-of loop within several other for loops

Is it possible to generate values from an Array of objects in the following way? const arr = [ { type: "color", values: [ { name: "Color", option: "Black", }, { name: "C ...