question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue.observable on an array does not really work

See original GitHub issue

Version

2.6.6

Reproduction link

https://jsfiddle.net/9L5ymbv7/

Steps to reproduce

If I do const todos = Vue.observable([]); and try to use it inside reactive context, it does not really work. For example, observing the length of the todos does not trigger re-run if I push to todos.

What is expected?

That observed array would be fully reactive.

What is actually happening?

There is no reactivity.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mitarcommented, Feb 15, 2019

Ehm, arrays are objects, no?

Should I make a feature request then for arrays to be supported as well?

0reactions
cotin18commented, Jun 17, 2020

@Justineo just do like this:

window.state = Vue.observable({ arr: [] }); or const state = Vue.observable({ arr: [] });

state.arr.push(‘test’);

Works like a charm for me 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue JS returns [__ob__: Observer] data instead of my array of ...
You're trying to log the data in created() before the asynchronous fetch completes, so it's still empty (except for the Observable that Vue...
Read more >
Home Rolled Store with Vue.observable (Vue 2) - Vue School
Vue.observable() makes it possible to create reactive data outside of a Vue component, thus making it a viable and flexible store solution ...
Read more >
On-demand Reactivity in Vue 3 - Toptal
This article will introduce you to new features and paradigms introduced in Vue 3 and demonstrate how you can leverage the new Composition...
Read more >
Where to Learn about observable Arrays and Objects : r/vuejs
Hi I just started learning Vue today, and am trying to make an app. I am probably borderline intermediate at JS.
Read more >
API - Vue.js
Please note that Vue does not come with a Promise polyfill, ... we recommend always working with the object returned by Vue.observable ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found