javascript - VueJS提交延迟导致数据错误
问题描述
我的 Vue 实例中有一个方法可以更新并从我的数据库中删除一个值。提交方法后,值会正确更新,但我需要在从前端删除值之前进行刷新。下面是我的方法:
async winBet(id, amount, bet) {
try {
this.bet.id = id
this.bet.amount = amount
this.bet.bet = bet
await this.$http.post("/user/winBet", this.bet);
} catch (err) {
console.log(err)
}
},
<form @submit="winBet(value._id, value.amount, value.bet)">
<button type="submit">Won</button>
</form>
我渲染列表,提交后不应该包含提交的元素,如下方式
<ul v-for="value in pendingBets">
<li>Bet: {{value}}</li>
</ul>
________________________________________________________________
mounted() {
fetch('http://localhost:4000/user/getUser', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
'email': this.myval.email
}),
})
.then(function (response) {
return response.json();
}).then(function (data) {
this.pendingBets = data[0].allBets
}.bind(this));
}
出于某种原因,我需要在从“pendingBets”中删除值之前进行刷新。有时它有效,有时我必须进行刷新。我还是 Vue 的新手,所以希望有人可以在这里向我指出正确的方向。先感谢您。
解决方案
我想出的解决方案是用一个短的 setInterval 实现一个 window.location.reload()。
推荐阅读
- sql - 如何修复 NEXTVAL 在插入查询中返回 null 但在 PostgreSQL 中单独执行时返回正确值?
- php - 如果当前用户是帖子的作者,则在前端显示图标
- android - Android:在 TextInputView 的边框内显示计数器
- amazon-web-services - AWS PHP SDK - Polly 忽略神经引擎
- fastapi - 自定义状态代码代替 500:使用 Postman 的 FastAPI 中的内部服务器错误
- python - 在 Python 中使用 while 循环在游戏中检查点
- firebase - 在 Flutter 测试中添加实时监听器
- java - Java:如何以排序方式迭代 LinkedList?
- python - 连续查找第一次出现的负值
- python - 从 Python 中的数据流中提取携带信息的 12 位