Despite the data changing properly, the modifications are not being reflected in the DOM. Below is a simple example illustrating this issue -
<template>
<input type="text" v-model="username" />
<p>{{error}}</p>
<button @click="saveData">Save</button>
</template>
<script>
export default {
data () {
model.error = ''; // adding a new property
return model; // 'model' is a global variable
}
methods: {
saveData() {
if (!this.username) {
this.error = 'Please enter the username!';
return;
}
// ... other code
}
}
};
</script>
Even after calling saveData()
, the error
variable contains the message for an unfilled username but does not display in the paragraph.
Interestingly, there's a workaround. By updating the username
property whenever the error
variable changes, the updates become visible.