I want to have a randomNumber variable inside a vue component. But in my template and in my script tag, the values never match.
using datas:
<template>
<div :data-number="randomNumber"
</template>
<script>
export default {
data (){
return { randomNumber: Math.random() * 1000}
},
mounted: function(){
console.log(this.randomNumber)
}
}
</script>
using computed property:
<template>
<div :data-number="randomNumber"
</template>
<script>
export default {
computed{
randomNumber: Math.random() * 1000
},
mounted: function(){
console.log(this.randomNumber)
}
}
</script>
Or passing the randomNumber as props from my parent component.
I expect data-number to be equal to this.randomNumber, but it's never the case.
I managed to get a workaround for my project, but I'm still interested in the solution here.
Any help will be much appreciated, thanks !
divbut it does work for me. My console display proper values so I don't see where is the problem (-_-) - Al-un