Skip to content

Instantly share code, notes, and snippets.

@DeaVenditama
Created October 21, 2020 14:57
Show Gist options
  • Save DeaVenditama/0cb39a845b81882237ae9b27b0670629 to your computer and use it in GitHub Desktop.
Save DeaVenditama/0cb39a845b81882237ae9b27b0670629 to your computer and use it in GitHub Desktop.
<template>
<h1>Conditional</h1>
<h3>{{ bilangan }}</h3>
<h4 v-if="ganjil">Ganjil</h4>
<h4 v-if="genap">Genap</h4>
<button v-on:click="randomNumber">Generate</button>
</template>
<script>
export default {
data(){
return{
bilangan : 1,
ganjil : false,
genap : false,
}
},
mounted(){
this.randomNumber();
},
methods: {
randomNumber(){
this.bilangan = Math.floor(Math.random()*100);
this.showHide();
},
showHide(){
if(this.bilangan%2==0){
this.genap = true;
this.ganjil = false;
}else{
this.genap = false;
this.ganjil = true;
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment