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
| import Vue from 'vue'
|
| Vue.directive('num', function (el, binding) {
| const min = binding.value.min
| const max = binding.value.max
| const _input = el
| _input.onkeyup = function (e) {
| let value = e.currentTarget.firstElementChild.value
| if (value.length == 1) {
| value = value.replace(/[^1-9]/g, '')
| } else {
| value = value.replace(/[^\d]/g, '')
| }
| if (min) {
| if (value < min) {
| value = min
| }
| }
| if (max) {
| if (value > max) {
| value = max
| }
| }
| e.currentTarget.firstElementChild.value = value
| }
|
| })
|
|