【发布时间】:2023-03-15 23:18:01
【问题描述】:
我有两个按钮,它们通过 v-if 标记根据变量显示。如果变量为假,则显示一个按钮,如果为真,则显示另一个。
只有当我在 chrome 中打开开发工具时,布尔变量才会更新……我不知道这是为什么。
视频:https://i.gyazo.com/95a90354fdcec849cc7e33aaa5e1d8b9.mp4
最后一帧截图:https://gyazo.com/ecc0cbfbc01cf6f472cea48c6cc89a4a
按钮代码
<div class="form-row float-right">
<button v-if="btnDisabled" class="btn btn-success" disabled style="margin-top: 25px;">
Save
</button>
<button v-else class="btn btn-success" style="margin-top: 25px;"
v-on:click="createAlert()">
Alert me when {{desiredPriceComputed}}
</button>
</div>
我的一些数据变量……
btnDisabled: true,
inputInvalid: false,
hideProduct: false,
hidePriceForm: false,
busy: false,
desiredPriceComputed 的函数(按钮变量从 true 变为 false。
desiredPriceComputed: function () {
let input = this.desiredPriceInput;
let pInput = parseFloat(this.desiredPriceInput);
if (input == "") {
this.inputInvalid = false;
this.btnDisabled = true;
this.cardAlert.desiredPrice = 0;
return '';
}
if (Number.isNaN(pInput)) {
this.inputInvalid = true;
this.btnDisabled = true;
this.cardAlert.desiredPrice = 0;
return '';
}
if (pInput < 0) {
this.inputInvalid = true;
this.btnDisabled = true;
this.cardAlert.desiredPrice = 0;
return '';
}
if (pInput > 1000000000) {
this.inputInvalid = true;
this.btnDisabled = true;
this.cardAlert.desiredPrice = 0;
return '';
}
this.inputInvalid = false;
this.btnDisabled = false;
this.cardAlert.desiredPrice = pInput.toFixed(2);
if (pInput > this.cardAlert.currentPrice) {
return '$' + pInput.toFixed(2) + " or higher";
}
else if (pInput < this.cardAlert.currentPrice) {
return '$' + pInput.toFixed(2) + " or lower";
}
else {
return '$' + pInput.toFixed(2);
}
}
其他一些重要的注意事项
我将 Vue 单文件组件与 ASP.NET MVC 剃须刀页面一起使用。
我目前正在通过 header 标签内的下面调用 Vue。
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
【问题讨论】:
标签: javascript vue.js