VueJS modal displaying data acts strangely

While using vueJS and Laravel, I encountered an issue with my modal losing its shape when I tried to display data in it. Even duplicate forms failed to show the data correctly. This occurred when I clicked on a button to open the modal and show the data.

https://i.sstatic.net/z7f3X.png

Additionally, I have a function in vue that takes a parameter, and I want to be able to click on a button in my table to display data related to an assistance and then show its actions.

<tr v-for="data in datosAsistencia" :key="data.codAsistencia">
                <td>{{ data.codAsistencia }}</td>
                <td>{{ data.codContrato }}</td>
                <td>{{ data.fecha }}</td>
                <td>{{ data.mensaje }}</td>
                <td>{{ data.nombre }}</td>
                <td>
                    <select @change="cambiarEstado(data.codAsistencia, $event)">
                        <option value="0" selected>{{data.estado}}</option>
                        <option value="en_proceso">En proceso</option>
                        <option value="finalizada">Finalizada</option>
                    </select>
                </td>
                <td><a href="#" class="btn btn-info" data-toggle="modal" data-target="#create" @click="visualizar(data.codAsistencia)">Visualizar</a></td>

The weirdest part is that if I start changing tabs in the tabPane, the modal shows up correctly in the end. I am not sure why this happens. Any help would be greatly appreciated.

Answer №1

Utilizing VueJS while still thinking in jQuery mode can be a challenge. One of the key advantages of VueJS is its model-binding feature, which automatically updates the view with any changes to the data.

Here is an example that may help. The data is connected to the v-model, ensuring that it updates seamlessly when the "selected" property is modified as declared.

<table>
<tr v-for="data in datosAsistencia" :key="data.codAsistencia">
    <td>{{ data.codAsistencia }}</td>
    <td>{{ data.codContrato }}</td>
    <td>{{ data.fecha }}</td>
    <td>{{ data.mensaje }}</td>
    <td>{{ data.nombre }}</td>
    <td>
        <a href="#" class="btn btn-info" data-toggle="modal" data-target="#create" @click="visualizar(data.id)">Visualize</a>
    </td>
</tr>
</table>
<div class="modal" v-if="selected">
    <label>Name</label>
    <input type="text" v-model="selected.nombre">
</div>
<script>
export default {
    data() {
        return {
            selected: null
        }
    },
    methods: {
        visualizar(id) => {
            let url = "/getDatosAsistencia/"+ id;
            axios
                .get(url)
                .then((response) => {
                    this.selected = response.data[0]
                }
        }
    }
}
</script>

Answer №2

I successfully solved the issue I was facing. Could someone help me with the @JoeGalind, I encountered a problem with duplication of data in my modal due to a for-each loop I used with jQuery. I have since removed the for-each loop.

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

rely on a fresh event starting at one

Despite my limited knowledge in javascript, I managed to create a simple js calendar that I am quite proud of. However, I have been facing a challenge for the past few days. You can view my calendar here: https://jsfiddle.net/ck3nsemz/ The issue I'm ...

The post method in Express.js is having difficulty parsing encoded data accurately

I'm currently working on an AngularJS code that sends a POST request like this: var req = { method: 'POST', url: 'http://localhost:3300/addInventoryItem', headers: { 'Content-Type': 'application/x-www-form- ...

React-dom is throwing a hook call error. How do I fix this?

I am looking to implement a global modal component using redux/toolkit for global management. Upon clicking the drop-down menu, I specify the message to display in the modal. I aim to close the modal by clicking either the Ok or Cancel button or the backgr ...

Clear navigation bar on top of a backdrop picture

I am currently exploring the most effective method to place my hero/background image behind a transparent Bootstrap 4 navbar. Some have suggested applying the background image to the body of the page, but I specifically want the background image only on th ...

I am unable to access the information from a .txt file using Ajax

I'm attempting to create a basic AJAX example, but I'm encountering issues getting it to function correctly. Below is the code I have: <script> function loadXMLDoc() { var xmlhttp; if (window.XMLhttpRequest) { ...

Turn off Chrome 69's autofill functionality

I've recently encountered an issue with Chrome's password autofill feature that has been troubling me for a few days now. This problem began when I was using Chrome version 69. After much trial and error, I found a solution by removing the id an ...

The MongoDB object type is not stored

Let me share my customized user schema below. var userSchema=mongoose.Schema({ //name:{type:String}, username: {type:String, required:true, unique:true}, password: {type:String, required:true}, habit: {type:Object, required:true} }); Howev ...

How can I retrieve values of selected checkboxes using the Express Data API?

I have a scenario where I need to retrieve data from input checkboxes only when the checkbox for my express post function is selected. There are 3 checkboxes with values of 1000, 2000, and 3000 as follows: <input type="checkbox" name=" ...

In my app.post request in node.js and express, the body object is nowhere to be found

Having an issue with node.js and express, trying to fetch data from a post request originating from an HTML file. However, when I log the request, the req.body object appears empty. I've added a console.log(req.body) at the beginning of my app.post(" ...

What is the best way to implement CSS styling in the existing Vue.js template?

Currently delving into the world of Vue.js, I've discovered that styling child components is achieved by referencing classes, ids, and tags defined in the component's template. Let's take a look at the App.vue component as an example: <st ...

When attempting to add objects to an indexedDB object store, an InvalidStateError is encountered

I have defined IndexedDB and IDBTransaction dbVersion = 1; var db; var dbreq; var customerData = { ssn: "444", name: "Bill", age: 35, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b0bbbebe92b1bdbfa2b3bcabfcb1bdbf"& ...

When using React.js, clicking on an answer option will change the color of all options, not just the one that was clicked

I'm currently working on my quiz page where all answer options change color when clicked. However, I only want the selected answer option to be colored based on its correctness. The data is being retrieved from a data.json array. export default functi ...

Injecting variables into the password reminder email in Laravel: a step-by-step guide

Is it possible to customize the URL of the password reset view using Laravel 4.1's new password broker feature? I would like to pass some additional data to the password reminder view for this purpose. After reviewing the documentation here: http://l ...

The JavaScript confirm function will provide a false return value

Is it necessary to display a confirmation message asking "Are you sure ..."? I have implemented the message, but the function return false; is not working when the user clicks NO. <script> function confirmDelete(){ var answer = confirm("Are you su ...

What steps should I take to address this 'key' alert?

My browser console is displaying the following error message: Warning: Each child in a list should have a unique "key" prop. See https://reactjs.org/link/warning-keys for more information. ExpenseList@http://localhost:3000/main.cfec1fef7369377b9a ...

Having difficulty in focusing on a textarea upon page initialization

I've been attempting to focus on a syncfusion textarea without success. Even after using this.$nextTick when the component mounts as instructed here, the textarea still doesn't receive focus. I also tried adding the same "focus to textarea" code ...

Is there a way to maintain the checked status of the checkboxes after a page refresh?

Is there a way to keep the checkboxes checked even after the page is refreshed in this code snippet? Any code sample or explanation on how to achieve this would be highly appreciated. The complete project code can be found here: https://github.com/Orelso/P ...

Tips for preventing tiny separation lines from appearing above and below unordered list elements

I am attempting to utilize twitter bootstrap to create a select-option style list. How can I eliminate the thin separation lines above and below the list of items? Refer to the screenshot: https://i.sstatic.net/1khEE.png Below is the visible code snippe ...

Is there a way to transform the searchParams function into an object? Changing from URLSearchParams { 'title' => '1' } to { title : 1 }

Is there a way to convert the searchParams function into an object, transforming from URLSearchParams { 'title' => '1' } to { title : 1 }? I need this conversion to be applied for all values in the URLSearchParams, not just one. Cur ...

Display the table upon completion of the form submission

I am trying to create a form where the table #mytable is only displayed after the form has been submitted. If nothing is entered in the form, the table should remain hidden. Any suggestions on how I can achieve this? <form action="" id="myform" method ...