Noob Coder Noob Coder - 4 months ago 67
Javascript Question

vuejs this.posts.$remove(postId) is not a function

im trying to remove an array element using $remove. but it says this.posts.$remove is not a function. Can anyone explain where am i wrong?

<button type="button" class="btn btn-danger" @click="deletePost(">Xxx</button>

vue instance:


this is my example data

my data

this is my console

enter image description here


I see in the tags that you are using VueJS 2. The $remove() method has been deleted:

As said in the migration guide, you should just use the splice() method:

methods: {
  removeTodo: function (todo) {
    var index = this.todos.indexOf(todo)
    this.todos.splice(index, 1)