[Vuejs]-Random Number doesn't print the result

1👍

You should call a method onclick and change random in data as follows:

var aleatori = new Vue({
    el:'#aleatori',
    data() {
        return{
              random:0
        }
    },
    methods:{
      randomNumber() {
            this.random = Math.floor(Math.random() * (10 - 1 + 1)) + 1
      }
    }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="aleatori">
     <button v-on:click="randomNumber">Aleatori</button>
     <p>{{ random }}</p>
</div>

Leave a comment