環(huán)境vue + elemntUI相關(guān)代碼https://codepen.io/eeeecw/pen...點(diǎn)擊預(yù)覽具體情景在輸入框的 change 事件里,我修改了輸入框的雙向幫定值,但不是每次都顯示在輸入框里。比如上面代碼,輸入框不支持小數(shù),每次輸入后,我都會(huì)在 change 事件里把數(shù)字轉(zhuǎn)成整數(shù),但是顯示的值還是原來(lái)的值但是如果在 change 事件里寫(xiě)一個(gè) setTimeout 去把數(shù)字轉(zhuǎn)成整數(shù),就回成功把最新值渲染出來(lái)。。。這是為什么?求原理?或者有什么更好的解決辦法?
vue數(shù)據(jù)更新視圖不實(shí)時(shí)更新的問(wèn)題,這是為什么?。?/h1>
3 回答

翻翻過(guò)去那場(chǎng)雪
TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
應(yīng)為num1初始值是1,你輸入1.3655后,通過(guò)Math.floor(this.value.num1)計(jì)算之后還是num1還是1,el-input-number內(nèi)部的watch沒(méi)有監(jiān)聽(tīng)到變化,el-input-number相關(guān)代碼如下:
watch: { value: { immediate: true, handler: function handler(value) { var newVal = value === undefined ? value : Number(value); if (newVal !== undefined) { if (isNaN(newVal)) { return; } if (this.precision !== undefined) { newVal = this.toPrecision(newVal, this.precision); } } if (newVal >= this.max) newVal = this.max; if (newVal <= this.min) newVal = this.min; this.currentValue = newVal; this.$emit('input', newVal); } } },
添加回答
舉報(bào)
0/150
提交
取消