0

I'm trying to learn Vue.js and was following the official guides. On the Reactivity Fundamentals tutorial I found out that the state, which is initialized as a reactive variable, is declared as a constant. Why are they doing this and why is this working?

<script setup>
import { reactive } from 'vue'

const state = reactive({ count: 0 })

function increment() {
  state.count++
}
</script>

<template>
  <button @click="increment">
    {{ state.count }}
  </button>
</template>
Top Snek
  • 71
  • 5
  • 1
    hint: it's `state.count` that is being changed, not `state` – Bravo Apr 20 '22 at 07:55
  • The linked answer does not apply to Vue. Vue's [reactivity](https://vuejs.org/api/reactivity-core.html#reactive) uses [proxies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy), which are a bit different. – tauzN Apr 20 '22 at 08:11
  • but a "const" is still a "const" - and I think that's the part the OP is having trouble with – Bravo Apr 20 '22 at 12:22

0 Answers0