Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #17 VxeNumberInput 无法手动输入小数点 #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/views/number-input/NumberInputTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<vxe-number-input v-model="demo1.value103" placeholder="超小尺寸" size="mini"></vxe-number-input>
</p>

小数间隔: {{ demo1.value503 }}

<p>
<vxe-number-input v-model="demo1.value500" placeholder="数值类型" type="number"></vxe-number-input>
<vxe-number-input v-model="demo1.value501" placeholder="数值间隔 1.4" type="number" step="1.4" clearable></vxe-number-input>
Expand Down
11 changes: 7 additions & 4 deletions packages/number-input/src/number-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ export default defineComponent({
inputMethods.dispatchEvent(evnt.type, { value: inputValue }, evnt)
}

const emitModel = (value: number | null, evnt: Event | { type: string }) => {
reactData.inputValue = value
const emitModel = (value: number | null, evnt: Event | { type: string }, writeToInput = true) => {
emit('update:modelValue', value ? Number(value) : null)
if (writeToInput) {
reactData.inputValue = value
}
inputMethods.dispatchEvent('input', { value }, evnt as any)
if (XEUtils.toValueString(props.modelValue) !== XEUtils.toValueString(value)) {
inputMethods.dispatchEvent('change', { value }, evnt as any)
Expand All @@ -264,7 +266,7 @@ export default defineComponent({
const value = inputValue ? Number(inputValue) : null
reactData.inputValue = inputValue
if (inpImmediate) {
emitModel(value, evnt)
emitModel(value, evnt, false)
} else {
inputMethods.dispatchEvent('input', { value }, evnt)
}
Expand Down Expand Up @@ -353,7 +355,8 @@ export default defineComponent({
inpNumVal = Number(inpStringVal)
}
}
emitModel(getNumberValue(inpNumVal), { type: 'check' })
const numValue = getNumberValue(inpNumVal)
emitModel(numValue, { type: 'check' })
}
}
}
Expand Down