Vue Js List使用Splice渲染更改数组

时间:2023-01-07 21:28:36
    let vm = new Vue({
        el:"#app",
        data:{
            users:[
                {
                    name:"Murad"
                },
                {
                    name:"Maxi"
                },

            ]
        }
    })

vm.users[1] = {name:"John"};

vm.users [1] = {name:“John”};

this is not work but

这不是工作但是

vm.users.splice(0,1,{name:"John"})

and after vm.users[1] = {name:"John"};

在vm.users [1] = {name:“John”}之后;

this is work Why after splice change array with index work?

这是工作为什么在splice改变数组与索引工作?

1 个解决方案

#1


2  

Vue doesn't trigger a change for a modified array value, but does for splice

Vue不会触发修改后的数组值的更改,但会针对拼接触发更改

https://vuejs.org/v2/guide/list.html#Mutation-Methods

Vue will automatically trigger for the following array functions:

Vue将自动触发以下数组函数:

  • push()
  • pop()
  • shift()
  • unshift()
  • splice()
  • sort()
  • reverse()

#1


2  

Vue doesn't trigger a change for a modified array value, but does for splice

Vue不会触发修改后的数组值的更改,但会针对拼接触发更改

https://vuejs.org/v2/guide/list.html#Mutation-Methods

Vue will automatically trigger for the following array functions:

Vue将自动触发以下数组函数:

  • push()
  • pop()
  • shift()
  • unshift()
  • splice()
  • sort()
  • reverse()