What is the best way to extract a specific field from a Vuetify table and send it via Axios?

Is there a way to extract only the field from a Vuetify table and post it using Axios? The code snippet below shows a table setup:

 <div id="app">
      <v-app id="inspire">
        <v-card>
          <v-card-title>
            <v-text-field
              v-model="search"
              append-icon="mdi-magnify"
              label="Search"
              single-line
              hide-details
            ></v-text-field>
          </v-card-title>
          <v-data-table
            :headers="headers"
            :items="students"
            :search="search"
          >
            <template  v-slot:item.status="{ item }">
              <v-btn v-if="item.status" @click="add(item)">Add</v-btn>
              
              <v-btn v-else disabled>Temporarily no access</v-btn>   
            </template>
            
          </v-data-table>
        </v-card>
      </v-app>
    </div>

Here is the corresponding script:

 const app = new Vue({
   el: '#app',
   vuetify: new Vuetify(),    
   data() {
         return {
           search: '',
           headers: [
             { text: 'Number list', align: 'start', value: 'id'},
             { text: 'Name', align: 'start', value: 'name'},
             { text: 'Options', value: 'status' }
           ],
           students: [
        {
          id: 1,
          name: pedro,
          status: activo,
        },
        {
          id: 2,
          name: juan,
          status: activo,
        },
        {
          id: 3,
          name: jose,
          status: activo,
        },
       ]
         };
       },
    methods: {
        add (item) {
        axios.post('http://localhost/list?id=' + item.id)
          .then(response => {
            this.response = response
        }).catch(e => {
          console.log(e)
        });
      },
    
    }
 });

The main issue I'm facing is that when clicking the button, I receive an error stating that the item is undefined. Additionally, I want to ensure that the student's status is active before proceeding with the post request.

Reference for the generated table image can be found here.

Edit

I forgot to include:

 @click="add(item)"

Even after adding this, the issue persists without any errors appearing in the console, despite having the catch block.

Answer №1

Attempt the following:

 <v-btn v-if="item.estado" @click="add(item)">Add</v-btn>

Second Attempt: Before proceeding, verify if item is being passed correctly by inserting the line below. This might aid in identifying the issue.

     <template v-slot:item.status="{ item }">
              <p>Debug item text: {{item}}</p>
              <v-btn v-if="item.status" @click="add(item)">Add</v-btn>
              
              <v-btn v-else disabled>Temporarily no access</v-btn>   
            </template>

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

Displaying a Variety of Images using React and HTML

I've encountered an issue with rendering images that have large file sizes. Whenever I try to upload and display multiple large image files, the performance becomes extremely slow. So my question is: Should the backend handle providing a URL for ver ...

Ways to showcase an item within additional items?

I'm struggling to properly display data in a table. My goal is to iterate through an object within another object inside an array and showcase the source, accountId, name, and sourceId in the table. https://i.sstatic.net/VVIuc.png <tbody clas ...

Testing actual HTTP requests in unit and integration tests with AngularJS

Attempting a request that was not mocked using $httpBackend.when in an Angular 1.x unit/integration test will lead to an error: Error: Unexpected request: GET /real-request Is there a way to perform actual HTTP requests with ngMock and the Karma+Jasmin ...

issues arise post-transpilation with creating errors

In order to practice, I decided to create a basic TypeScript project. If it could be helpful, here is my ts.config: { "compilerOptions": { "target": "es2016", "module": "commonjs", "outDir": "./dist", "esModuleInterop": true, "forceC ...

Tips for toggling the visibility of the 'more' button based on the number of lines in a paragraph

While writing code using HTML, CSS, JavaScript, and Bootstrap, I encountered an issue with the "show more" link. The problem arises when there is only one line in the paragraph; I would like the "show more" link to be hidden and not displayed on the screen ...

Can the format of FormData be switched from multipart/form-data to form-urlencoded?

I am currently utilizing JavaScript to send form data via a POST request var request = new XMLHttpRequest(); request.open("POST", "/validate", false); request.send(new FormData(form)); // form is document.getElementById("#form") My backend is built with ...

Creating a custom loading page in Next.js 13: A step-by-step guide

Hello, I am currently working on implementing a loading page for my website to enhance the user experience during a longer loading time. I have created a simple functional component that displays a loading message and imported it into my layout.jsx file in ...

Presenting a ui-router modal while maintaining the parent state's refresh-free appearance

I have implemented a unique feature in my angular app called modalStateProvider. It allows me to easily have modals with their own URLs. // Implementing the modalStateProvider app.provider('modalState', [ '$stateProvider', function ...

tips on utilizing the JSON information transmitted from the backend

$.ajax({ url: '{{ URL('reports/groupsUsersGet') }}', dataType: "json", data: { group_id : $('#group').val(), }, success: function(data) { <li>"i need to insert variable here"</li> }, error: function (data) ...

retrieveStyle() rooted framework Category

I have implemented a customized Native Base style theme following the instructions in this link. Imports: import material from './native-base-theme/variables/material'; import getTheme from './native-base-theme/components'; return ( ...

Launch the sidebar window using jQuery

I've been attempting to create something similar to this. However, I'm having trouble replicating it exactly. What I've attempted I've managed to create a replica, but the issue is that the buttons are fixed. Could setting the left ...

Turn off the Right click option on an .aspx page, but allow it on a Hyper

Can the right click be disabled on a webpage while still allowing it on hyperlinks within the same page? I am aware that I can disable right click, but if there is a way to allow it on hyperlinks, please provide the code. The main reason for disabling rig ...

What is the best way to retrieve the parent iFrame ID when a blur event occurs in the TinyMCE

I have successfully implemented 4 TinyMCE editors on a single page. My goal is to obtain the editor ID when the user exits the TinyMCE editor and place the editor's HTML content into a textarea. While I can achieve this using the blur event in Chrome, ...

How can I best access the object being exposed on the webpage using <script type="text/json" id="myJSON">?

In our current project, we are successfully using AMD modules to organize and structure our code. One idea I have is to create an AMD module that accesses a script tag using a jQuery ID selector and then parses the content into JSON format. Here's an ...

Unable to store the user's input information in the database

I've been attempting to incorporate an "add" button feature that saves/adds/inserts data into my table. I have inputted some text in the form of tags (input type), but unfortunately, it doesn't seem to be functioning properly. Despite conducting ...

Is there an improved guide available for using Netbeans' new language support plug-in?

Recently, I've started working with a new server side language that is based on Javascript. It has similar functionalities to PHP, but uses Javascript syntax for processing server responses and handling logic. In terms of text editors, Netbeans is my ...

What are some strategies for enhancing state management in ReactJS?

Currently, I am retrieving information via an API and storing it in the state. This information needs to be filtered based on what I type into an input field. However, I have encountered an issue where if I delete a letter from the input, I am unable to re ...

The Transparent Quirk in Three.js

Hey there! I'm working on displaying a 3D avatar on my website that allows users to apply textures to the character. I'm hoping to enable users to create transparent textures so they can see the model underneath. Right now, when implementing tran ...

Is there a way Axios distinguishes between local and production environments?

I am currently facing an issue while setting up Vue + axios in a way that the base URL varies depending on the site's URL. Localhost for vue: http://localhost:8080 API for localhost: On the server, vue is set to: and the corresponding API is: ...

Bootstrap offers an improved method for arranging elements in columns and rows, especially when you need to omit certain ones

Is there a more efficient method for aligning elements using Bootstrap? Here is my current approach: <div className="row"> <div className="col-3 font-weight-bold"> Item Name ...