Suppose in a vue 3 component I have the following
<script>
export default {
props: {
minimumDays: Number
},
data() {
return {
days: this.minimumDays + Math.ceil(Math.random() * 40)
}
},
methods: {
increaseDays() {
this.days = this.days + 1
}
}
}
</script>
As you can see I am using the value of a prop to compute the initial value of a mutable 'data' variable called "days." I was first trying to use the computed
object to do this but received an error indicating that computed data should not be mutated.
Is this acceptable, to reference a prop
in the establishment of data
? Is there a correct technique for taking a bit of data from a prop, and using it, once modified, to establish mutable state in a component?