Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
accebb77
Commit
accebb77
authored
Jan 12, 2017
by
baiyaaaaa
Committed by
杨奕
Jan 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input-number auto adjust min max value
parent
bbd779c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
21 deletions
+16
-21
packages/input-number/src/input-number.vue
packages/input-number/src/input-number.vue
+15
-20
test/unit/specs/input-number.spec.js
test/unit/specs/input-number.spec.js
+1
-1
No files found.
packages/input-number/src/input-number.vue
View file @
accebb77
...
...
@@ -96,26 +96,20 @@
}
},
data
()
{
// correct the init value
let
value
=
this
.
value
;
if
(
value
<
this
.
min
)
{
this
.
$emit
(
'
input
'
,
this
.
min
);
value
=
this
.
min
;
}
if
(
value
>
this
.
max
)
{
this
.
$emit
(
'
input
'
,
this
.
max
);
value
=
this
.
max
;
}
return
{
currentValue
:
value
currentValue
:
0
};
},
watch
:
{
value
(
value
)
{
const
newVal
=
Number
(
value
);
if
(
!
isNaN
(
newVal
)
&&
newVal
<=
this
.
max
&&
newVal
>=
this
.
min
)
{
value
:
{
immediate
:
true
,
handler
(
value
)
{
let
newVal
=
Number
(
value
);
if
(
isNaN
(
newVal
))
return
;
if
(
newVal
>=
this
.
max
)
newVal
=
this
.
max
;
if
(
newVal
<=
this
.
min
)
newVal
=
this
.
min
;
this
.
currentValue
=
newVal
;
this
.
$emit
(
'
input
'
,
newVal
);
}
}
},
...
...
@@ -178,11 +172,12 @@
},
setCurrentValue
(
newVal
)
{
const
oldVal
=
this
.
currentValue
;
if
(
newVal
<=
this
.
max
&&
newVal
>=
this
.
min
&&
oldVal
!==
newVal
)
{
this
.
$emit
(
'
change
'
,
newVal
,
oldVal
);
this
.
$emit
(
'
input
'
,
newVal
);
this
.
currentValue
=
newVal
;
}
if
(
newVal
>=
this
.
max
)
newVal
=
this
.
max
;
if
(
newVal
<=
this
.
min
)
newVal
=
this
.
min
;
if
(
oldVal
===
newVal
)
return
;
this
.
$emit
(
'
change
'
,
newVal
,
oldVal
);
this
.
$emit
(
'
input
'
,
newVal
);
this
.
currentValue
=
newVal
;
},
handleInput
(
value
)
{
const
newVal
=
Number
(
value
);
...
...
test/unit/specs/input-number.spec.js
View file @
accebb77
...
...
@@ -249,7 +249,7 @@ describe('InputNumber', () => {
const
inputNumber
=
vm
.
$refs
.
inputNumber
;
vm
.
value
=
100
;
vm
.
$nextTick
(
_
=>
{
expect
(
inputNumber
.
currentValue
).
to
.
be
.
equal
(
5
);
expect
(
inputNumber
.
currentValue
).
to
.
be
.
equal
(
10
);
vm
.
value
=
4
;
vm
.
$nextTick
(
_
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment