Is there a way to disable my button after just one click, or when the timeOut
function is running? Currently, I have code that allows the button to be clicked only if my moneyValue
is greater than money
, and it's working perfectly. Now, within that same if statement, I also want the button to be disabled when a certain condition is met (//if function is running). Any ideas on how to achieve this?
Here's the code snippet:
data:{
crashValue: 1,
money: 1000,
moneyValue: 0,
betAmount: 0,
buttonDisabled: false
},
methods:{
placeBet(){
let asd = this.money - this.moneyValue;
this.money = asd;
this.betAmount = 1000 - asd;
this.startTimer();
},
checkAmount(){
if(this.moneyValue > this.money // HELP NEEDED HERE !){
this.buttonDisabled = true;
} else {
this.buttonDisabled = false;
}
},
startTimer () {
let interval = 90;
if (this.crashValue > 2.15) {
interval = 80;
}
// Additional conditions here...
var tessst = setTimeout(this.crashFunction, interval);
},
placeBet(){
let asd = this.money - this.moneyValue;
this.money = asd;
this.betAmount = 1000 - asd;
this.startTimer();
},
checkAmount2(){
if(this.moneyValue <= 0){
this.buttonDisabled = true;
} else {
this.buttonDisabled = false;
}
},
cashOut(){
clearTimeout(this.tessst);
console.log(Number(this.betAmount * this.crashValue).toFixed(2));
}}
<input @keyup="checkAmount(); checkAmount2()" v-model="moneyValue" class="numbImp" type="number" />
<p>
Your bet {{ betAmount }}
</p>
<button class="placeBet" :disabled="buttonDisabled" @click="placeBet(); checkAmount(); checkAmount2">Place bet</button>
<button class="stopCrash" @click="cashOut">Cash out</button>
<p>
You currently have {{ money }} money
</p>