Skip to content
Advertisement

is There an easy way to get all data from vuejs?

I have this data’s is there a way to get all of these? already tried this._data.forEach but it is not working thanks!

data() {
  return {
    childData: '',
    credit: '',
    company: '',
    email: '',
    first_name: '',
    middle_name: '',
    terms: '',
    last_name: '',
    phone: '',
    mobile: '',
    fax: '',
    street: '',
    city: '',
    country: '',
    state: '',
    zip_code: '',
    as_of: '',
    account_number: '',
    website:'',
    open_balance: '',
    notes: '',
    files: null,
  }

Advertisement

Answer

Vue uses underscore as a prefix for its internal properties. You should avoid using them.

The data object for an instance is accessible via the $data property.

https://v2.vuejs.org/v2/api/#vm-data

So within an instance you can get that object using this.$data.

In the question you mentioned trying to use forEach. Not sure what you’re trying to do but objects don’t have a native forEach method. The usual looping mechanisms for an object are available on $data, such as for/in or grabbing the array of keys:

Object.keys(this.$data)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement