async function changeNumber(target) { let param = { url: '/cart/number', argument: { id: localStorage.getItem('userId'), goodsId: target.parentElement.parentElement.dataset.goodsid, // number: --target.nextElementSibling.value } } if (target.className == 'deleteGoods') { param.argument.number = --target.nextElementSibling.value if (param.argument.number == 0) { target.nextElementSibling.value = 1 target.disabled = true return } } if (target.className == 'addGoods') { param.argument.number = target.previousElementSibling.value target.previousElementSibling.previousElementSibling.disabled = false } let res = await ajax_post(param) if (res.code == 1) { this.renderCarList() } } 改变为同步函数怎么改变
时间: 2023-06-09 17:07:34 浏览: 137
可以直接将async关键字去掉,改为普通的函数即可。如下所示:
function changeNumber(target) {
let param = {
url: '/cart/number',
argument: {
id: localStorage.getItem('userId'),
goodsId: target.parentElement.parentElement.dataset.goodsid,
// number: --target.nextElementSibling.value
}
}
if (target.className == 'deleteGoods') {
param.argument.number = --target.nextElementSibling.value
if (param.argument.number == 0) {
target.nextElementSibling.value = 1
target.disabled = true
return
}
}
if (target.className == 'addGoods') {
param.argument.number = target.previousElementSibling.value
target.previousElementSibling.previousElementSibling.disabled = false
}
let res = ajax_post(param)
if (res.code == 1) {
this.renderCarList()
}
}
阅读全文