Using a single-file template, I would like to have a button that shows "click here" if an array is empty and shows the value if it is populated. The ajax is working fine and the object is getting updated, but the button doesn't re-render. What am I doing wrong here?
<template>
<span>
<button
v-if="value.app_token.length"
class="btn btn-outline-primary btn-sm"
disabled
>Mobile App Token: {{ value.app_token[0].token }}</button>
<button v-else class="btn btn-primary btn-sm" @click="getToken">Click to get Mobile App Token</button>
</span>
</template>
<script>
module.exports = {
props: ["value"],
methods: {
getToken() {
axios
.get("/patients/getToken/" + this.value.id)
.then(response =>
this.value.app_token.splice(
0,
this.value.app_token.length,
response.data
)
)
.catch(error => console.log(error));
}
}
};
</script>