简体   繁体   English

如何仅从 vuetify 表中获取字段以在 axios 中发布

[英]How can I get only the field from a vuetify table to post in axios

How can I get only the field from a vuetify table to post by in axios, I have a table as I show in the following code如何仅从 vuetify 表中获取字段以在 axios 中发布,我有一个表,如下面的代码所示

 <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">Add</v-btn>
              
              <v-btn v-else disabled>Temporarily no access</v-btn>   
            </template>
            
          </v-data-table>
        </v-card>
      </v-app>
    </div>

and from script I have the following code从脚本我有以下代码

 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)
        });
      },
    
    }
 });

What I want to do is that when it is clicked I only sent the id per post with axios but when I click it I get an error in the console that says that item is undefined that is my main error, and as you can see I need it to be first verify that the student's status is active.我想要做的是,当它被点击时,我只用 axios 发送每个帖子的 id 但是当我点击它时,我在控制台中收到一个错误,说该项目未定义,这是我的主要错误,正如你所看到的我需要首先验证学生的状态是否处于活动状态。 Below I also add an image of the generated table for further reference.下面我还添加了生成表的图像以供进一步参考。

table reference表参考

Try:尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用“multiple”道具获取 Vuetify Select 字段以与数据库中的 axios 数据进行交互? - How do I get a Vuetify Select field with the “multiple” prop to interact with axios data from database? 如何将文本从 Vuetify 的 v-text-field 复制到剪贴板? - How can I copy text from Vuetify's v-text-field to clipboard? 如何使用 axios 从 json 获取数据? (反应) - How can I get data from json with axios? (React) 如何从 Axios 中的 HTTP 错误获取状态码? - How can I get the status code from an HTTP error in Axios? 如何从axios promise对象获取数据? - How can I get data from axios promise object? 我无法使用 axios 从我的发布请求中获取我的 httpOnly cookie - I can't get my httpOnly cookie from my post request using axios 我如何通过第一张表从第二张表中获取字段,并使用javascript中的外键? - How can I get field from second table via first table with foreign key from javascript? 如何将此获取发布请求转换为 axios 发布请求? - How can I convert this fetch post request into an axios post request? 我如何使用 Vue axios 从从 API 获得的数据发布数组数据 - How can i post Array Data with Vue axios from Data obtained from an API 无法使用Axios从Http POST请求获取标头 - Can't get headers from Http POST request with Axios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM