我真的理解vue.js,但是我的代码不能很好地工作。现在,我已经尝试通过使用delete按钮exist same来删除选中的行信息。即使我在第一行按下按钮,也不会删除,但我可以从第二行删除信息。
我在代码中使用了split方法。我查看了vue.js网站,我使用的是$delete方法,但它不起作用。
我真的很想了解vue.js和Typescript。有什么建议吗?我的代码如下。
<template>
<div>
<table>
<thead>
<tr>
<th>ID</th>
<th>username</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<tr v-for="(user,index) in users" :key="user.id">
<td>{{user.id}}</td>
<td>{{user.email}}</td>
<td><v-btn class="btn btn-danger" @click="deleteRow(index)">delete</v-btn></td>
</tr>
</tbody>
</table>
</div>
</template>
<script lang="ts">
import {Component,Vue} from 'nuxt-property-decorator'
import axios from 'axios'
@Component({})
export default class extends Vue{
users:any=[]
deleteRow(index:any){
this.users.splice(this.users,index)
};
async mounted(){
const response = await axios.get("https://jsonplaceholder.typicode.com/users");
this.users = response.data;
}
}
</script>发布于 2020-08-06 22:22:57
我认为您没有正确使用splice。你的方法应该是:
deleteRow(index:any) {
this.users.splice(index, 1);
}发布于 2020-08-06 22:24:59
您将splice与参数start as index和第二个用于删除计数的参数误用了:
this.users.splice(index,1)https://stackoverflow.com/questions/63285598
复制相似问题