Skip to content

Commit d8673d5

Browse files
committed
update
1 parent fa88ba0 commit d8673d5

File tree

11 files changed

+690
-22
lines changed

11 files changed

+690
-22
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"devDependencies": {
3131
"@rollup/plugin-commonjs": "^24.0.1",
3232
"@rollup/plugin-node-resolve": "^15.0.1",
33+
"@vue/compiler-sfc": "^3.2.47",
3334
"@vue/eslint-config-typescript": "^11.0.2",
3435
"@vue/test-utils": "^2.2.10",
3536
"eslint": "^8.34.0",
@@ -42,6 +43,7 @@
4243
"rollup-plugin-filesize": "^9.1.2",
4344
"rollup-plugin-node-resolve": "^5.2.0",
4445
"rollup-plugin-typescript2": "^0.34.1",
46+
"rollup-plugin-vue": "^6.0.0",
4547
"typescript": "^4.9.5",
4648
"vue": "2.6.0"
4749
},

rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import vue from 'rollup-plugin-vue'
12
import typescript from 'rollup-plugin-typescript2'
23
import commonjs from 'rollup-plugin-commonjs'
34
import resolve from 'rollup-plugin-node-resolve'
@@ -40,6 +41,7 @@ export default [
4041
}),
4142
resolve(),
4243
commonjs(),
44+
vue(),
4345
filesize()
4446
],
4547
external: ['vue']

src/component.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/component.vue

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<template>
2+
<input
3+
v-number="config"
4+
type="text"
5+
autocomplete="off"
6+
:value="maskedValue"
7+
class="v-number"
8+
@change="change"
9+
@input="input"
10+
@blur="(evt) => $emit('blur', evt)"
11+
@focus="(evt) => $emit('focus', evt)"
12+
>
13+
</template>
14+
15+
<script lang="ts">
16+
import Vue from 'vue';
17+
import directive from './directive'
18+
import { cloneDeep, CustomInputEvent, Input } from './core'
19+
import defaultOptions from './options'
20+
21+
Vue.directive('number', directive)
22+
23+
const options = cloneDeep(defaultOptions)
24+
25+
export default Vue.extend({
26+
name: 'VueNumber',
27+
props: {
28+
value: {
29+
required: true,
30+
type: [Number, String]
31+
},
32+
nullValue: {
33+
type: [Number, String],
34+
default: () => options.nullValue
35+
},
36+
masked: {
37+
type: Boolean,
38+
default: false
39+
},
40+
reverseFill: {
41+
type: Boolean,
42+
default: options.reverseFill
43+
},
44+
prefill: {
45+
type: Boolean,
46+
default: options.prefill
47+
},
48+
precision: {
49+
type: Number,
50+
default: () => options.precision
51+
},
52+
minimumFractionDigits: {
53+
type: Number,
54+
default: () => options.minimumFractionDigits
55+
},
56+
decimal: {
57+
type: String,
58+
default: () => options.decimal
59+
},
60+
min: {
61+
type: Number,
62+
default: () => options.min
63+
},
64+
max: {
65+
type: Number,
66+
default: () => options.max
67+
},
68+
separator: {
69+
type: String,
70+
default: () => options.separator
71+
},
72+
prefix: {
73+
type: String,
74+
default: () => options.prefix
75+
},
76+
suffix: {
77+
type: String,
78+
default: () => options.suffix
79+
}
80+
},
81+
data() {
82+
return {
83+
maskedValue: this.value,
84+
unmaskedValue: '' as Input | undefined
85+
}
86+
},
87+
computed: {
88+
emittedValue() {
89+
return this.masked ? this.maskedValue : this.unmaskedValue
90+
},
91+
config() {
92+
return {
93+
nullValue: this.nullValue,
94+
masked: this.masked,
95+
reverseFill: this.reverseFill,
96+
prefill: this.prefill,
97+
precision: this.precision,
98+
minimumFractionDigits: this.minimumFractionDigits,
99+
decimal: this.decimal,
100+
min: this.min,
101+
max: this.max,
102+
separator: this.separator,
103+
prefix: this.prefix,
104+
suffix: this.suffix
105+
}
106+
}
107+
},
108+
watch: {
109+
value(val) {
110+
if (this.unmaskedValue !== val) {
111+
this.maskedValue = val
112+
}
113+
}
114+
},
115+
methods: {
116+
input(event: CustomInputEvent) {
117+
const { target } = event
118+
this.maskedValue = target.value
119+
this.unmaskedValue = target.unmaskedValue
120+
this.$emit('input', this.emittedValue)
121+
},
122+
change() {
123+
this.$emit('change', this.emittedValue)
124+
}
125+
}
126+
});
127+
</script>

0 commit comments

Comments
 (0)