I generate a random number when the model is mounted. I want to remove the "0." The 0. and decimal. I tried adding Math.round() but that gives me a NaN. Can someone tell me what I am missing.
new Vue({
el: '#app',
data: {
mixNumber:''
},
mounted: function(){
this.myFunction();
},
methods:{
myFunction: function () {
this.mixNumber = Math.random();
this.roundNumber=Math.round();
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
My ID is: {{mixNumber}}
</div>
You can use the following code:
new Vue({
el: '#app',
data: {
mixNumber:'',
roundNumber: ''
},
mounted: function(){
this.myFunction();
},
methods:{
myFunction: function () {
this.mixNumber = Math.random();
this.roundNumber = this.mixNumber.toString().split(".")[1];
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
My ID is: {{roundNumber}}
</div>