全空格问题优化
This commit is contained in:
parent
0366391848
commit
c2114f9122
19
src/main.js
19
src/main.js
|
|
@ -83,19 +83,18 @@ Vue.directive('no-whitespace', {
|
|||
const input = el.querySelector('input') || el.querySelector('textarea');
|
||||
if (!input) return;
|
||||
|
||||
input.addEventListener('input', (event) => {
|
||||
const handleInput = (event) => {
|
||||
const value = event.target.value.trim();
|
||||
if (value === '') {
|
||||
if (value === '' || value.replace(/\s/g, '') === '') {
|
||||
//设置event.target.value的值为undefined,为了触发v-model的更新
|
||||
input.removeEventListener('input', handleInput);
|
||||
event.target.value = '';
|
||||
input.dispatchEvent(new Event('input'));
|
||||
input.addEventListener('input', handleInput);
|
||||
}
|
||||
});
|
||||
|
||||
input.addEventListener('blur', (event) => {
|
||||
const value = event.target.value.trim();
|
||||
if (value === '') {
|
||||
event.target.value = '';
|
||||
}
|
||||
});
|
||||
};
|
||||
input.addEventListener('input', handleInput);
|
||||
input.addEventListener('blur', handleInput);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue