Questions tagged [vue-composition-api]

A set of additive, function-based APIs for VueJS that allow the flexible composition of component logic.

The APIs proposed in this API provides the users with more flexibility when organizing component code. Instead of being forced to always organize code by options, code can now be organized as functions each dealing with a specific feature. The APIs also make it more straightforward to extract and reuse logic between components, or even outside components.

Basic example

<template>
  <button @click="increment">
    Count is: {{ state.count }}, double is: {{ state.double }}
  </button>
</template>

<script>
import { reactive, computed } from 'vue'

export default {
  setup() {
    const state = reactive({
      count: 0,
      double: computed(() => state.count * 2)
    })

    function increment() {
      state.count++
    }

    return {
      state,
      increment
    }
  }
}
</script>

Related Tags

Resources

1515 questions
212
votes
8 answers

ref vs reactive in Vue 3?

Looking at some examples of some people's preview tutorials for Vue 3. [Currently beta right now] I've found two examples: Reactive