Categories
Vue Answers

How to get data as object with Vue.js?

Spread the love

Sometimes, we want to get data as object with Vue.js.

In this article, we’ll look at how to get data as object with Vue.js.

How to get data as object with Vue.js?

To get data as object with Vue.js, we can use the this.$data property.

For instance, we write

<script>
export default {
  //...
  methods: {
    log() {
      console.log(this.$data.a);
      console.log(this.$data.b);
      console.log(this.$data.foo);
    },
  },
  //...
};
</script>

to get the a reactive property with this.$data.a.

Likewise, we get the b reactive property with this.$data.b and the foo reactive property with this.$data.foo.

Conclusion

To get data as object with Vue.js, we can use the this.$data property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *