insertInputTxt(insertTxt, ref = "textarea") {
var aInput = this.$refs[ref].$el; // 如果使用的是组件输入框需要添加.$el
var startPos = aInput.selectionStart;
var endPos = aInput.selectionEnd;
if (startPos === undefined || endPos === undefined) return;
var txt = aInput.value;
var result =
txt.substring(0, startPos) + insertTxt + txt.substring(endPos);
aInput.value = result;
aInput.focus();
this.$nextTick(() => {
const pos = startPos + insertTxt.length;
aInput.setSelectionRange(pos, pos);
});
},
vue input在焦点处添加内容
于 2022-01-10 11:15:02 首次发布