Looping through a Vue Bootstrap modal using a v-for directive

I am working on a Vue Bootstrap modal placed within a v-for loop. I need to replace the '1' in both 'v-b-modal.modal-1' and 'modal-1' with the index value, which I can access as {{ index }} while looping through the items. However, I am struggling to find a way to dynamically add this index to the end of each identifier.

<div v-for="(movie, index, i) in movies">
  <b-button :key="index" :v-b-modal="'modal-' + index">Launch demo modal</b-button>
  <b-modal :id="'modal-' + index" title="BootstrapVue">
    <p class="my-4">Hello from modal!</p>
  </b-modal>
</div>

Answer №1

When considering the ability to apply modifiers dynamically, the answer is No; it must be static.

However, in relation to a Bootstrap modal, I came across an interesting approach during my research for a solution.

I have found that you can achieve dynamic manipulation by passing the modifier as a value, similar to an id, and since the value is a JS expression, you have flexibility in how you handle it.

<b-button v-b-modal="'modal-1'">Launch demo modal</b-button>

<div v-for="(movie, index, i) in movies">
  <b-button v-b-modal="'modal-1'">Launch demo modal</b-button>
  <b-modal id="modal-1" title="BootstrapVue">
    <p class="my-4">Hello from modal!</p>
  </b-modal>
</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

Restrict Text Input Field to Accept Only Specific Domain

Hey there! I've set up a text input box for users to link their Tripadvisor page to their profile. I want to make sure that when they paste the URL in, it is checked for the correct format. For example, if someone pastes: or , then allow the link. Ho ...

What causes the discrepancy in calculating marginTop on a desktop browser compared to a mobile browser?

In the top screenshot, you can see a representation of my Pixel 6XL connected to my laptop in USB debug mode. The checkered area represents the URL bar on the Chrome browser displayed on my Pixel device. Below that, the second screenshot shows the view fr ...

Gulp is showing an error of "Module Not Found" despite the module being present in the project

I've come across an unexpected issue and I'm at a loss for solutions. As part of my exploration into JS unit testing, I am configuring gulp with Jasmine. However, when I run my gulp build, I encounter the following error: Error: Cannot find modu ...

Is your Firebase .push() function encountering errors when trying to update the database?

I am facing an issue with a component that checks if a user has already upvoted a post. The logic is such that if the user has upvoted a post before, they cannot upvote it again. However, if they haven't upvoted it yet, they should be able to do so. ...

Encountering a VUE error during unit testing operations

Upon adding a test unit and running it using npm run unit, I encountered an error causing the test to fail. However, everything appears to be working fine when I run npm run dev. It seems that when running with npm run unit, the sass-loader is unable to re ...

Implementing a variety of threshold colors in Highcharts

Exploring this Highcharts fiddler: http://jsfiddle.net/YWVHx/97/ I'm attempting to create a similar chart but encountering some issues. The fiddler I'm currently working on is here: (check out the edit below!) The key difference in functionalit ...

Guide to ensuring the navbar remains at the top of the webpage following an image

I am attempting to create a sticky navbar that stays at the top of the page once the header has been scrolled past. It should have a similar effect as shown in this example on codepen.io, but with the addition of an image that stretches across most of the ...

Exploring the Enzyme library in React to trigger an onClick event with a specific parameter

In my quest to simulate an onClick method in my unit tests using Enzyme for React, I have encountered various tutorials on simulating an onClick event that takes an event e. For example: handleClick(e) { // Does something } .... <MyComponent onCli ...

Experiencing difficulties with mocha and expect while using Node.js for error handling

I'm in the process of developing a straightforward login module for Node. I've decided to take a Test-Driven Development (TDD) approach, but since I'm new to it, any suggestions or recommended resources would be greatly appreciated. My issu ...

Looking to incorporate an additional column 'LastName' that can be used for filtering in the Angular data table code. This column will be included if it is present in the data

function applyFilter(filterValue: string) { filterValue = filterValue.toLowerCase(); --- return filtered result return this.dataSet.filter( (item: any) => item.name ? item.name.toLowerCase(). ...

Why do I keep encountering invalid errors with Vuelidate and TailwindCSS?

I am struggling to comprehend why I keep encountering validation errors. The logic seems fine, so it must be something wrong with my :class bindings. Even though I know I will feel foolish once I figure it out, I have gone through numerous tutorials and st ...

What could be the reason for the Azure server sending a Bad Request response?

My NodeJS application is currently hosted on Azure server and all APIs are functioning correctly, providing the expected responses. The issue arises when trying to run a GET API like the following: https://demoapp.azurewebsites.net/mymenu?userId=piyush.d ...

developing a deferred commitment by utilizing promise objects

Hi everyone, I've encountered an issue with a JavaScript promise question that's throwing errors function delay(n) { return new Promise((resolve) => setTimeout(resolve, n*1000)); } The expected output should be "It is now 2 seconds later" ...

Could a javascript loop be created to continuously activate a button with each iteration?

I have just started learning javascript and I am in the process of creating a website where users can change the background by simply clicking on a button. It's working perfectly fine so far, but I want to add another feature where the background imag ...

Sending data from jQuery modal to the final input field

In my latest project, I have developed a modal window that features a table with rows of input boxes and buttons: <table class="datatable tablesort selectable paginate full" width="100%"> <tbody> ...

Guide to activating a watcher once the page finishes loading

One of my challenges involves a watcher calling a method: watch: { 'list.items' (n, o) { this.doSomething() } } Every time the page loads, new values are added to list.items like this: methods: { fetchLists(){ axios.get('/ ...

Utilizing global SCSS styles in a Vue project alongside distinct SCSS mixin and variable files

In the process of developing a Vue 3 app with scss, I have encountered a challenge. I have three separate stylesheet files - _mixins.scss, _variables.scss, and base.scss. To ensure that the mixins and variables are accessible in all components without manu ...

Storing JSON data in a MongoDb database using the Sails.js framework

I'm looking to build my database using an external API. To begin, I've created a function called loadData(req, res){} in my DBController that retrieves data from the API in JSON format. Now, I want to save this imported JSON data into my mongoDB ...

Prevent onlick actions until JavaScript function has completed

I run a dynamic quiz website using PHP, JavaScript, and MySQL. The quiz consists of multiple choice questions with answer options displayed on four buttons. <input type = "button" value="$alt1" onClick="changeQuestion('alternative1'); this.st ...

The functionality of uploading files in Dropzone.js is not supported on Windows operating systems

I am currently working on a file uploader using dropzone functionality. I will share the code with you shortly, but first let me outline the problem: My setup consists of an Ubuntu machine running the server code in node.js using the multer library. The f ...