【问题标题】:vuejs this.posts.$remove(postId) is not a functionvuejs this.posts.$remove(postId) 不是函数
【发布时间】:2017-03-21 04:15:16
【问题描述】:

我正在尝试使用 $remove 删除数组元素。但它说 this.posts.$remove 不是一个函数。谁能解释我哪里错了?

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

vue 实例:

deletePost(postId){
        console.log(postId);
        this.posts.$remove(postId);
      },

这是我的示例数据

这是我的控制台

【问题讨论】:

    标签: javascript arrays vue.js vuejs2


    【解决方案1】:

    我在标签中看到您正在使用 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)
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-23
      • 2019-12-11
      • 2021-06-26
      • 2019-03-24
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多