laravel Vuejs切片功能不是反应性的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41209348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:57:01  来源:igfitidea点击:

Vuejs slice function not reactive

laravelvue.js

提问by Patrick Bellerive

I'm using - laravel - blade -vuejs

我正在使用 - laravel -blade -vuejs

For one case i have splice not reactive on array. So i have an ul/li ( i have remove css and other stuff )

对于一种情况,我的拼接对阵列没有反应。所以我有一个 ul/li(我已经删除了 css 和其他东西)

<ul>
        <template v-for="(user, index) in availableUsers"  >
        <li v-bind:data-user="user.id" v-bind:data-index="index" >
            @{{user.fullName}}
            <button id=btnRemove>                            
        </li>
   </template>
</ul>

in my vue instance code i have a function removeFromAvailable. i do a call to myvue.availableUsers.slice(index, 1). the method receive the good index.

在我的 vue 实例代码中,我有一个函数 removeFromAvailable。我打电话给 myvue.availableUsers.slice(index, 1)。该方法接收良好的索引。

removeFromAvailable : function(index) {
        console.log(index);
        myVue.availableUsers.slice(index, 1);
}

It's still in the list. I'm confused because it's first time it's not working.

它仍然在列表中。我很困惑,因为这是第一次它不起作用。

Any idea why it's not reactive?

知道为什么它不是反应性的吗?

回答by Dwight

I believe you need to set the variable again. slicejust returns a copy of the changed array, it doesn't change the original instance.

我相信您需要再次设置变量。slice只返回已更改数组的副本,它不会更改原始实例。

removeFromAvailable(index) {
  this.availableUsers = this.availableUsers.slice(index, 1);
}