Displaying various pop-up notifications upon clicking a table element

I am completely new to VueJS and I'm currently working on populating a table with various columns, one of which contains a button that triggers the opening of a modal. There are three different types of modals that can be opened based on certain conditions. Below is my attempt to solve this issue:

For reference, I have included a link to my jsfiddle after the code snippet.

HTML

<div id="app">

  <!-- Main table element -->
  <b-table striped hover :items="items" :fields="fields" >
    <template slot="name" slot-scope="item">
      {{item.value.first}} {{item.value.last}}
    </template>
    <template slot="isActive" slot-scope="item">
      {{item.value?'Yes :)':'No :('}}
    </template>
    <template slot="actions" slot-scope="item">
      <div v-if="item.item.age < 15">
        <b-btn v-b-modal.modal1 size="sm" @click="details(item.item)">Details</b-btn>
      </div>
      <div v-else-if="item.item.age > 26">
        <b-btn v-b-modal.modal2 size="sm" @click="details(item.item)">Details</b-btn>        
      </div>
      <div v-else>
        <b-btn v-b-modal.modal3 size="sm" @click="details(item.item)">Details</b-btn>
      </div>
    </template>
  </b-table>

  <b-modal id="modal1">
    modal 1
  </b-modal>

  <b-modal id="modal2">
    modal 2
  </b-modal>
  
  <b-modal id="modal3">
    modal3
  </b-modal>
</div>

VueJS

new Vue({
  el: '#app',
  data: {
    items: [{
      isActive: true,
      age: 40,
      name: {
        first: 'Dickerson',
        last: 'Macdonald'
      }
    }, 
    // more object entries here...
    }],
    fields: {
      name: {
        label: 'Person Full name',
        sortable: true
      },
      age: {
        label: 'Person age',
        sortable: true
      },
      isActive: {
        label: 'is Active'
      },
      actions: {
        label: 'Actions'
      }
    }
  },
  methods: {
    details(item) {
      //gets some data. Write 3 different functions to fetch data accordingly 
    }
  }
})

Style:

#app {
  padding: 20px;
  height: 500px;
}

Update:

After introducing pagination, I encountered the same bug described below in my application. To replicate the issue, navigate to a different page and try opening all the available modals. Some may not open. Visit my fiddle: fiddle

Observation:

I noticed that I am only able to open one modal per page when switching pages from the initial view.

Bug Description:

When clicking on the button for the rows, particularly those sharing the same modal type, I encounter a strange behavior where some do not trigger the corresponding popup. For instance, if we consider the entries P and Q in the column both linked to modal 1, clicking on P opens the modal while clicking on Q does not. Although the exact cause of this bug seems elusive, any guidance or pointers in resolving it would be greatly appreciated. Thank you.

Answer №1

This strange behavior is difficult to explain (possibly a bug in bootstrap-vue). However, if you make the following replacement:

<b-btn v-b-modal.modal1 size="sm" @click="details(item.item)">Details</b-btn>
<b-btn v-b-modal.modal2 size="sm" @click="details(item.item)">Details</b-btn>
<b-btn v-b-modal.modal3 size="sm" @click="details(item.item)">Details</b-btn>

with:

<b-btn v-b-modal="'modal1'" size="sm" @click="details(item.item)">Details</b-btn>
<b-btn v-b-modal="'modal2'" size="sm" @click="details(item.item)">Details</b-btn>
<b-btn v-b-modal="'modal3'" size="sm" @click="details(item.item)">Details</b-btn>

it should resolve the issue.

I hope this solution works for you.

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

Demonstrating reactivity: updating an array property based on a window event

One example scenario involves setting specific elements to have an active class by assigning the property "active" as true (using v-bind:class). This property is modified within a foreach loop, after certain conditions are met, through the method "handleSc ...

Ways to remove items from Vuex store by utilizing a dynamic path as payload for a mutation

I am looking to implement a mutation in Vuex that dynamically updates the state by specifying a path to the object from which I want to remove an element, along with the key of the element. Triggering the action deleteOption(path, key) { this.$store.d ...

Guide on creating a Docker image from a Vue.js application and deploying it to a Nexus repository using GitLab's CI/CD pipeline

I am currently working on a Vuejs application that needs to be built in order to push into Nexus as a Docker image. All the Vuejs contents are stored on a GitLab repository. The pipeline consists of these stages: setup (retrieve information from pipeline ...

Update the headers of the axios.create instance that is exported by Axios

I have a single api.js file that exports an instance of axios.create() by default: import axios from 'axios' import Cookies from 'js-cookie' const api = axios.create({ baseURL: process.env.VUE_APP_API_URL, timeout: 10000, headers ...

A guide to isolating shared HTML code in a Vue App Component

I have a Vue application that consists of multiple components. Each component contains duplicated code at the top of its template: <section v-if="status || warn" class="messages"> <div class="status">{{status}}</div> <div class="w ...

Using the Fetch API to set variables in Vue 2: Asynchronous Task

As someone who is new to working with async tasks, I'm having trouble understanding why my fetch API call isn't updating my Vue variable even though the data appears correctly in the console log. I've tried using Async/Await without success. ...

Tips for loading and updating data simultaneously in VUEJS from a single input

Currently, the data is displayed in a span tag with an input for updating it Is it possible to fetch data from an API, load it into an input field, update the input with new information, and send it back? What are the best approaches for achieving this? ...

Elevate the element from the choice API to the organization API using this.$parent

I recently developed a Vue 3 component called "Tab" using the option API. Here is the code: export default { name: "Tab", props: { name: {required: true}, iconClass: {required: true}, selected: {default: false} }, da ...

Issue with Axios GET request due to CORS restrictions

I am currently developing a VueJS application and I am trying to integrate the Yahoo! Shopping API (documentation: ) in order to retrieve products based on their barcode. However, I am encountering a CORS error that is preventing the API request from being ...

Tips on placing custom loading components in Nuxt/Vue applications

I recently used nuxt and followed a helpful guide on creating a custom loading component. You can find the instructions here While the custom loader does work, I noticed that it appears in the same position as the original nuxt loader bar: https://i.stac ...

Using Internet Explorer with Vuejs may require adding a polyfill for Promise support

Having no prior experience with Vuejs, I found myself in a situation where I needed to debug code for Internet Explorer. The first problem was fixing all arrow Functions, which wasn't too difficult to handle. The second issue is that I am not able to ...

Can you use the OR operator between vee-validate3 rules?

For this input, the value can be either a username or email address. Here is an example: <ValidationProvider name="email" rules="username || email" v-slot="{ errors, valid }"> <v-text-field v-model="something" :error-messages="er ...

The attribute 'positive_rule' is not found within the structure '{ addMore(): void; remove(index: any): void;'

data() { return { positive_rule: [ { positive_rule: "", }, ], }; }, methods: { addMore() { this.positive_rule.push({ positive_rule: "", }); }, ...

Vue.js dynamic HTML elements are constantly changing and evolving

Is it possible to dynamically add elements to the content? See example below: <template> {{{ message | hashTags }}} </template> <script> export default { ... filters: { hashTags: function(value) { ...

The value of data in Vue.js remains stagnant even after reassignment

In my data setup, I have defined the following: data() { return { mdrender: '', markdown: '' }; }, Additionally, I am working with this function: methods: { interpretVars: function(markdown) { $.ge ...

Is it possible to selectively implement a transition in VueJS based on certain conditions?

My goal is to design an alert box component with a customizable reveal transition, which can be optional. Here's a simplified version of what I have in mind: <template> <transition v-if="withTransition"> <b-alert v-bind="th ...

Exploring solutions for handling asynchronous issues with vue3-google-map

While working with a Vue library for managing Maps called vue3-google-map, I encountered an issue when trying to define certain polylines that would not allow me to select the center of the marked area: Here is my map template: <template> <Goo ...

Can the `lang` attribute be used in a `style` tag to specify the CSS preprocessor language for VueJS? Are there any disadvantages to using this method?

Occasionally, I notice people incorporating code like this: <style lang="scss"> ... </style> <style lang="stylus"> ... </style> I checked the documentation for the style tag and found that lang is not a valid a ...

What comes after fetching data with axios but before the webpage is rendered?

Struggling to dynamically render my DOM based on data retrieved from an axios get request. The timing seems off as there is a delay between the request and receiving the data. Essentially, I need to display a 'cancel' button if there is informati ...

What is the method for enabling or disabling a text field based on the chosen value in a b-form-select?

Can anyone assist me with enabling or disabling an input text field based on the values selected in a b-form-select element? Your help would be greatly appreciated. ...