首页 > 解决方案 > 拼接方法问题

问题描述

我正在从数组中删除一个元素:

this.my_events.splice(this.current_event);
this.current_event=null;
this.old_event=null;
jQuery('#eventModal').modal('hide');

当我在一个数组中添加三个或更多项目然后删除其中任何一个时,它会删除所有项目并返回 null 而不刷新页面。我正在使用Vue.js

如果我随后刷新页面,则会显示这两个元素。这是什么问题?

标签: javascriptlaravel

解决方案


您没有指定要删除的索引位置。

尝试这个:

 this.my_events.splice(index, 1); // the 1 represents how many items to delete
        this.current_event=null;
        this.old_event=null;
        jQuery('#eventModal').modal('hide');

推荐阅读