Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_admin
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
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_admin
Commits
334e469b
Commit
334e469b
authored
Jul 24, 2023
by
yaya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:限制金额输入
parent
23504995
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletion
+12
-1
src/views/goods/edit.vue
src/views/goods/edit.vue
+12
-1
No files found.
src/views/goods/edit.vue
View file @
334e469b
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<el-input
v-model=
"goods.name"
/>
<el-input
v-model=
"goods.name"
/>
</el-form-item>
</el-form-item>
<el-form-item
label=
"价格"
prop=
"price"
>
<el-form-item
label=
"价格"
prop=
"price"
>
<el-input
v-model=
"goods.price"
placeholder=
"0.00"
>
<el-input
v-model=
"goods.price"
type=
"number"
placeholder=
"0.00"
@
input=
"limitInput"
>
<template
slot=
"append"
>
元
</
template
>
<template
slot=
"append"
>
元
</
template
>
</el-input>
</el-input>
</el-form-item>
</el-form-item>
...
@@ -155,6 +155,17 @@ export default {
...
@@ -155,6 +155,17 @@ export default {
this
.
init
()
this
.
init
()
},
},
methods
:
{
methods
:
{
limitInput
(
value
)
{
this
.
goods
.
price
=
(
''
+
value
)
// 第一步:转成字符串
.
replace
(
/
[^\d
^
\.]
+/g
,
''
)
// 第二步:把不是数字,不是小数点的过滤掉
.
replace
(
/^0+
(\d)
/
,
'
$1
'
)
// 第三步:第一位0开头,0后面为数字,则过滤掉,取后面的数字
.
replace
(
/^
\.
/
,
'
0.
'
)
// 第四步:如果输入的第一位为小数点,则替换成 0. 实现自动补全
.
match
(
/^
\d
*
(\.?\d{0,2})
/g
)[
0
]
||
''
// 第五步:最终匹配得到结果 以数字开头,只有一个小数点, 而且小数点后面只能有0到2位小数
},
init
:
function
()
{
init
:
function
()
{
if
(
this
.
$route
.
query
.
id
==
null
)
{
if
(
this
.
$route
.
query
.
id
==
null
)
{
return
return
...
...
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