5

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?

3
  • 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 Commented Jan 13, 2017 at 17:58
  • Code is here jsfiddle.net/apokjqxx/69. Computed propertis working fine for object and not for arrays by default. Commented Jan 13, 2017 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 Commented Jan 13, 2017 at 18:17

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Works fine. Also i've updated jsfiddle for use multidemensoal array, hope it will helpfull for anyone - jsfiddle.net/apokjqxx/73

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.