input-safe.vue
877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<template>
<Input :value="currentValue" v-bind="$attrs" v-on="$listeners" />
</template>
<script>
import xss from 'util/xss';
export default {
name: 'input-safe',
props: ['value'],
created() {
this.$listeners.input = this.input;
},
data() {
return {
currentValue: this.value
};
},
watch: {
value(val) {
this.currentValue = val;
}
},
methods: {
input(val) {
if (typeof val === 'string') {
this.currentValue = xss.replaceIllegal(val);
} else {
this.currentValue = val;
}
this.$emit('input', this.currentValue);
if (this.currentValue !== val) {
this.$Message.error('输入内容有敏感字符,已自动清除');
}
}
}
};
</script>