0
    let vm = new Vue({
        el:"#app",
        data:{
            users:[
                {
                    name:"Murad"
                },
                {
                    name:"Maxi"
                },

            ]
        }
    })

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

this is not work but

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

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

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

1 Answer 1

2

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

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

Vue will automatically trigger for the following array functions:

  • push()
  • pop()
  • shift()
  • unshift()
  • splice()
  • sort()
  • reverse()
Sign up to request clarification or add additional context in comments.

2 Comments

I know vue doesn't trigger a change for a modified array value but your change array with splice after you can change array with index see my example
@MuradSofiyev JavaScript is single threaded. Doing a splice will queue up an update. You then change the value, then the update happens.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.