Vue 3 Composition API data() Function

With the Composition API, Vue 3 no longer uses data(). Use ref() or reactive() in setup() to manage your component state.

In Vue 2, the data() option in the Options API returns an object with your component’s state, like a simple count value.
export default {  data() {     return {       count: 0     }   } }

Reactive Data in the Vue 3 Composition API

In Vue 3’s Composition API, there’s no data() function. Instead, you define reactive state inside the setup() function using ref() or reactive().

Example: ref()

<script setup>import { ref } from 'vue'   const count = ref(0) </script>   <template>   <button @click="count++">Clicked {{ count }} times</button> </template>

Example: reactive()

<script setup>import { reactive } from 'vue'   const state = reactive({   count: 0,   name: 'Vue 3' }) </script>   <template>   <button @click="state.count++">     Clicked {{ state.count }} times   </button>   <p>{{ state.name }}</p> </template>
Also Read: Best Vue Component Libraries to Build Stunning Frontends

Key Takeaway

  • In the Vue 3 Composition API, there is no data() function.
  • Use ref() for primitive values, and for any value you might fully replace later (primitive or complex).
  • Use reactive() for objects or arrays when you mostly update their properties directly.

Related Resources

Related
Vue

When building complex UIs with drag-and-drop functionality and nesting draggable components, this is a common use case. This guide will show you how to use…

07 Oct, 2025
Vue

Launching a startup means moving fast, testing ideas and building products that can scale quickly if they gain traction. That’s why many founders turn to…

03 Oct, 2025
Vue

Vue.js is one of the versatile JavaScript frameworks used to build dynamic web applications because of its great simplicity, performance and flexibility features. Although it’s…

29 Sep, 2025
Request a Quote Schedule a Meeting