所以我要尝试做的是,当我第一次点击时,进度栏的宽度为37.5%,而当我第二次点击时,百分比上升为100%,而不是0。有人可以解释为什么?这是我的代码:
HTML:
<div class="progress-bar progress-bar-striped bg-success progress-bar-animated" role="progressbar" aria-valuemin="0" aria-valuemax="8000" :style="{width: enemyBar + '%'}">
<strong>HP: \{{enemyHealth}} / 100</strong>
</div>
VUEJS:
this.enemyBar = this.damage / this.enemyHealth*100;
//damage: 3000 health: 5000 and progressbar left with 37.5 percent of width.
if(this.enemyBar < 0) {
return this.enemyBar = 0;
}
if(this.enemyBar > 100) {
return this.enemyBar = 100;
}
this.enemyHealth -= this.damage;
if(this.enemyHealth < 0) {
return this.enemyHealth = 0;
}