最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vuejs2: How to re-render array computed properties when array changed - Stack Overflow

programmeradmin0浏览0评论

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

`/`   

What is best way to use puted properties for array?

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

I have array named List and created puted property putedList 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/apokjqxx/69/`   

What is best way to use puted properties for array?

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

Share Improve this question edited Jan 13, 2017 at 17:48 maxxdev asked Jan 13, 2017 at 17:43 maxxdevmaxxdev 3132 gold badges5 silver badges14 bronze badges 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 – georaldc Commented Jan 13, 2017 at 17:58
  • Code is here jsfiddle/apokjqxx/69. Computed propertis working fine for object and not for arrays by default. – maxxdev 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/2016/02/06/mon-gotchas – georaldc Commented Jan 13, 2017 at 18:17
Add a ment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论