3 回答

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊
我能夠解決您的問(wèn)題,但是您需要在代碼中引入一個(gè)新變量
HTML:
<div id="app">
<input type="text" v-model="input" @input="handleInput">
<p>{{ updated_value }}</p>
</div>
JS:
new Vue({
el: "#app",
data() {
return {
input: null,
updated_value: null
}
},
methods: {
handleInput(e) {
this.input = e.target.value;
this.updated_value = e.target.value ? e.target.value.toString().toUpperCase()
: e.target.value;
}
}
});
摘要:
1)使用新變量(updated_value)存儲(chǔ)輸入的大寫(xiě)版本,并將其用作<p>
2的值。這確保輸入值不會(huì)被更新,從而不會(huì)導(dǎo)致游標(biāo)跳轉(zhuǎn)的問(wèn)題
添加回答
舉報(bào)