The Vue.js component experiencing issues with the Foundation 6 modal functionality

I'm facing an issue with my vue.js single file component. I have a button that is supposed to open a modal with a video from zurb foundation. However, every time I click the button, the page reloads without showing any errors in the console or network section. Below is the code snippet from my home.vue:

<a data-open="video" class="button warning" href="">WATCH VIDEO</a>

<div id="video" class="reveal" data-reveal>
    <div class="lead">
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="flex-video">
        <iframe width="1280" height="720" :src="url" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

Even though the url is correct and the video is being fetched from YouTube, the page still reloads when the button is clicked.

Answer №1

When incorporating vue with JavaScript plugins, it is recommended to utilize directives. This approach proves to be more effective when dealing with jQuery plugins and Zurb Foundation JavaScript plugins. More information can be found here

Answer №2

Could you provide us with the full code so we can better assist you? It would be difficult for us to help with just a snippet of the code. However, you should at least include something like the following.

HTML file:

<a @click="popup()">WATCH VIDEO</a>
<div id="video"></div>

Vue file:

methods: {
    popup() {
        $('#video').foundation('open');
    }
}

Answer №3

To eliminate the href="" attribute in the A tag, follow the steps below:

<a data-open="video" class="button warning">WATCH VIDEO</a>

Answer №4

When Foundation is initialized, it creates a new element that serves as the overlay for your modal. This overlay is visible to users and is generated when you activate Foundation by calling $(document).foundation(); after the Foundation script has been loaded.

However, if your modal (the original data-reveal element) is not within the user's view when foundation() is triggered, the overlay will not be created.

To ensure that Foundation is initialized properly within your component, you can add the following code:

  mounted() {
    $(document).foundation();
  }

By doing this, Foundation will be initialized again with your modal element in view, resulting in the creation of the overlay.

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

A guide on using jCrop to resize images to maintain aspect ratio

Utilizing Jcrop to resize an image with a 1:1 aspect ratio has been mostly successful, but I've encountered issues when the image is wider. In these cases, I'm unable to select the entire image. How can I ensure that I am able to select the whole ...

Is there a way to retrieve the values of a checkbox from a location outside the form where it is initially defined?

After successfully developing a script that deletes rows from a table when a checkbox is selected, I encountered an issue where the values of the checkboxes were not accessible outside of the form action they were placed in. The checkboxes and correspondin ...

Strategies for temporarily storing values within md-list-item in AngularJS

I am attempting to populate a list with items using material icons. The issue is that the values are being added permanently when the material icon is clicked, disregarding the save and discard buttons at the bottom of the card. My goal is to add values te ...

What sets apart computed, state, and action in MobX?

Currently, I am delving into MobX and grappling with the concepts of computed, state, and action individually. Do they serve similar purposes? One aspect of MobX that intrigues me is deciphering the disparity between computed properties and state. My unde ...

Enhancing data binding in Angular 2.0 with string interpolation

In my script, I am working with a string that goes like this: {name} is my name. Greeting {sender} Is there a module available in Angular 2.0 that allows me to use something similar to the string.format() function in C#? I understand that it can be achie ...

Refining the options in security question dropdown menus

Firstly: The title should mention filtering security options in dropdown lists, but it seems I'm restricted from using the term questions or question in the title. I came across this code example, but it appears to be outdated. Does anyone know why a ...

Unable to link to 'mdMenuTriggerFor' as it is not a recognized attribute of 'button'

During the execution of my angular application using ng serve, I encounter the following error: Can't bind to 'mdMenuTriggerFor' since it isn't a known property of 'button' Despite importing all the necessary components, I a ...

Using the useState hook in a loop can sometimes result in a unique key error

Trying to add multiple items for rendering in my browser, but encountering an issue after clicking addItem. The item does render, however, I am getting the following error message: 'Warning: Each child in a list should have a unique ""key"" ...

Tool for obfuscating client-side files using node.js

I'm in search of a tool similar to the one found at but in the form of a node.js module, allowing for obfuscation of client-side js files prior to transmission. The tool mentioned above performs various tasks, with its most crucial function being th ...

Quickly Share Documents within a Folder

I currently have a server set up with the following file structure: - index.js /client -index.html -about.html -signup.html -style.css Within the index.js file, I have implemented an express server. When the user navigates to /, it should display the ...

The Slide Out Menu functioned properly in HTML, but it seems to be malfunctioning when implemented in PHP

I recently implemented a slide-in and out menu with a hamburger icon to open it and an X icon to close it. The functionality was perfect until I integrated it into PHP and WordPress. Initially, I placed the script in the header section before the meta tags ...

What is the best way to stretch the background image across both the footer and navbar for my app?

Here is the code snippet I am currently working with: <template> <v-app> <AppBar></AppBar> <v-main> <router-view></router-view> </v-main> <Footer></Footer> ...

What is the best approach for retrieving values from dynamically repeated forms within a FormGroup using Typescript?

Hello and thank you for taking the time to read my question! I am currently working on an Ionic 3 app project. One of the features in this app involves a page that can have up to 200 identical forms, each containing an input field. You can see an example ...

Implementing the MVC pattern in the app.js file for a Node.js and Express web application

After completing several tutorials on nodejs, mongodb, and express, I have gained a solid understanding of the basics such as: The main controller file being app.js. Third party modules stored in their designated node_modules directory. Template files pl ...

Updating the handler function for AutoComplete with Checkbox in Material UI using React JS

I am looking to include an <AutoComplete /> field in my form. The options for this field are fetched through a get request, and here is the result displayed in the console. [ { "uid": "c34bb0ed-9f63-4803-8639-a42c7e2a8fb0&q ...

Issues with jQuery slide operation

I'm facing an issue with jQuery and I can't figure out where it's coming from. Here is the error message that keeps showing up in the console: Uncaught TypeError: Object [object Object] has no method 'getElement' script_16.js:46Un ...

Changing the hidden input value to the data-id of a selected <a> element

I've set up a form with a dropdown menu and subdropdowns, generated using a foreach loop through a @Model. When I click on one of the options, I want the value of my hidden input field to match the data-id of the clicked item. This is what I have in ...

Tips for preventing a React component from re-fetching data when navigating back using the browser button

In my React app using Next.js and the Next Link for routing, I have two pages set up: /product-list?year=2020 and /product-list/details?year=2020&month=4 Within the pages/product-list.js file, I am utilizing React router to grab the query parameter ye ...

Vue's unshift method only appends new items to the beginning of an

Could you help me with a problem similar to this one: The array I am working with looks like this: remate: {id:1, lotes: [{id:1, nombre: lalala}, {id:2, nombre: lololo}]} My issue arises when attempting to add new items to remate.lotes. While the push m ...

Is there a way to update the color of a button once the correct answer is clicked? I'm specifically looking to implement this feature in PHP using CodeIgniter

Within my interface, I have multiple rows containing unique buttons. Upon clicking a button, the system verifies if it corresponds to the correct answer in that specific row. The functionality of validating the responses is already functional. However, I a ...