11<template >
22 <div class =" el-number-range" >
3- <el-input :style =" {width}" type =" number" v-model.number =" minValue" />
3+ <el-input
4+ :style =" {width}"
5+ type =" number"
6+ v-model.number =" minValue"
7+ @blur =" clampMin($event)"
8+ @focus =" handleFocus($event, 'min')"
9+ />
410 <span class =" separator" >{{ separator }}</span >
5- <el-input :style =" {width}" type =" number" v-model.number =" maxValue" />
11+ <el-input
12+ :style =" {width}"
13+ type =" number"
14+ v-model.number =" maxValue"
15+ @blur =" clampMax($event)"
16+ @focus =" handleFocus($event, 'max')"
17+ />
618 </div >
719</template >
820<script >
@@ -52,12 +64,7 @@ export default {
5264 return this .value [0 ]
5365 },
5466 set (val ) {
55- if (this .isNum (val)) {
56- val = this .clamp (val)
57- if (this .isNum (this .maxValue )) val = Math .min (val, this .maxValue )
58- } else {
59- val = undefined
60- }
67+ if (val === ' ' ) val = undefined
6168 this .$emit (' input' , [val, this .maxValue ])
6269 }
6370 },
@@ -66,24 +73,32 @@ export default {
6673 return this .value [1 ]
6774 },
6875 set (val ) {
69- if (this .isNum (val)) {
70- val = this .clamp (val)
71- if (this .isNum (this .minValue )) val = Math .max (val, this .minValue )
72- } else {
73- val = undefined
74- }
75- /**
76- * 配合v-model使用
77- */
76+ if (val === ' ' ) val = undefined
7877 this .$emit (' input' , [this .minValue , val])
7978 }
8079 }
8180 },
8281 methods: {
82+ clampMin (event ) {
83+ this .$emit (' blur' , event , ' min' )
84+ if (this .minValue === undefined ) return
85+ let val = this .clamp (this .minValue )
86+ if (this .maxValue !== undefined ) val = Math .min (val, this .maxValue )
87+ this .$emit (' input' , [val, this .maxValue ])
88+ },
89+ clampMax (event ) {
90+ this .$emit (' blur' , event , ' max' )
91+ if (this .maxValue === undefined ) return
92+ let val = this .clamp (this .maxValue )
93+ if (this .minValue !== undefined ) val = Math .max (val, this .minValue )
94+ this .$emit (' input' , [this .minValue , val])
95+ },
96+ handleFocus (event , position ) {
97+ this .$emit (' focus' , event , position)
98+ },
8399 clamp (val ) {
84100 return Math .max (this .min , Math .min (this .max , val))
85- },
86- isNum : n => typeof n === ' number'
101+ }
87102 }
88103}
89104 </script >
0 commit comments