Im trying the <script setup> syntax in vue and wondering why reactivity is not working. What’s wrong here?
<template>
<button @click="changeButtonText">{{ buttonText }}</button>
</template>
<script setup>
import { ref } from 'vue'
let buttonText = ref("Foo")
function changeButtonText() {
buttonText = "Bar"
}
</script>
Tried without ref().
Tried with buttonText = ref("Bar"). No effect
>Solution :
In your function you have to change
buttonText = "Bar" to buttonText.value="Bar"
For more info on reactivity see: https://vuejs.org/api/reactivity-core.html#ref