Noo*_*der 2 javascript arrays vue.js vuejs2
即时尝试使用$ remove删除数组元素.但它说this.posts.$ remove不是一个函数.任何人都可以解释我错在哪里?
<button type="button" class="btn btn-danger" @click="deletePost(post.id)">Xxx</button>
Run Code Online (Sandbox Code Playgroud)
vue实例:
deletePost(postId){
console.log(postId);
this.posts.$remove(postId);
},
Run Code Online (Sandbox Code Playgroud)
这是我的示例数据
这是我的控制台
我在标签中看到您正在使用VueJS 2.该$remove()方法已被删除:http://vuejs.org/v2/guide/migration.html#Array-prototype-remove-removed
如迁移指南中所述,您应该只使用以下splice()方法:
methods: {
removeTodo: function (todo) {
var index = this.todos.indexOf(todo)
this.todos.splice(index, 1)
}
}
Run Code Online (Sandbox Code Playgroud)