[Vuejs]-How to set default value for a pair of buttons based on API response? VueJS

0👍

It is likely that isMandatory‘s value is changing depending on the response from the API call you are making. When the page is first loaded, it will be whatever default value you gave it, and when the API returns a response later, the page isn’t being refreshed.

I would need more information on how your code is structured, but my current guess is that you need to turn your isMandatory into a ref.

For example, if your code looks something like this:

<script setup>
  isMandatory = false;

  // -> some API call handling
  isMandatory = apiResponse
</script>
<template>
  ...
</template>

Turn it into something like:

<script setup>
  isMandatory = ref(false);

  // -> some API call handling
  isMandatory.value = apiResponse
</script>
<template>
  ...
</template>

Then template will reactively change whenever the value of isMandatory changes.

Leave a comment