javascript - Is it possible to discard data errors in a Vue instance? -


i have lot of variables in vue instance modified via api calls. initial value not important.

i hoping there way not define them upon instantiation of vm not work:

vm = new vue({    el: "#app",    data: {}  });  vm.number = 3
<div id="app">    {{ number }}  </div>

if replace data: {} data: { number: null } code runs fine.

what avoid have litany of such declarations - is there way not declare data variables upon instantiation?

not really.

the docs explain how reactivity works in vue follows:

when pass plain javascript object vue instance data option, vue walk through of properties , convert them getter/setters using object.defineproperty.

...

the getter/setters invisible user, under hood enable vue perform dependency-tracking , change-notification when properties accessed or modified.

...

due limitations of modern javascript (and abandonment of object.observe), vue cannot detect property addition or deletion.

so in plain terms, in order data value reactive , updated when api call returns, property must present time of instantiation because vue cannot detect addions or deletions.

that being said, can sort of fake suggested @gskema using placeholder object , attaching properties object. these changes indeed picked vue.

so do:

data: {   api: null } 

and attach api values api property when returned, , reference data api.number etc.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -