Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have array named List and created computed property computedList for him. When i update value of array it's not showing in html, but in console i see thar array is updated.

`https://jsfiddle.net/apokjqxx/69/`   

What is best way to use computed properties for array?

Maybe is exists way to trigger to re-render computed property?

share|improve this question
    
Some code would help. Do you have a jsfiddle showing the problem? Computed properties should work just fine and show updated values if the properties they reference update as well – georaldc Jan 13 at 17:58
    
Code is here jsfiddle.net/apokjqxx/69. Computed propertis working fine for object and not for arrays by default. – user3816475 Jan 13 at 18:01
1  
It's a vuejs limitation where it cannot pickup changes if you directly modify the array that way. vuejs.org/2016/02/06/common-gotchas – georaldc Jan 13 at 18:17
up vote 6 down vote accepted

Due to limitations in JavaScript, Vue cannot detect the changes to an array like this: this.list[1] = 'vueman'

You have to use Vue.set or vm.$set as explained here to trigger state updates in the reactivity system, like follwoing:

  this.$set(this.list, 1, 'vueman')

see updated fiddler here.

share|improve this answer
    
Thanks! Works fine. Also i've updated jsfiddle for use multidemensoal array, hope it will helpfull for anyone - jsfiddle.net/apokjqxx/73 – user3816475 Jan 13 at 18:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.