[英]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.下面我还添加了生成表的图像以供进一步参考。
Try:尝试:
<v-btn v-if="item.estado" @click="add(item)">Add</v-btn>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.