diff --git a/example/components/input/readme.md b/example/components/input/readme.md index 72be753..6dc68a4 100644 --- a/example/components/input/readme.md +++ b/example/components/input/readme.md @@ -709,6 +709,7 @@ | show-word-limit | 是否显示输入字数统计,只在 `type = "text"` 或 `type = "textarea"` 时有效 | Boolean | true / false | —— | | behavior | 简约风格设置(simplicity:简约 normal:正常 type=textarea时不生效) | String | 'normal'/'simplicity' | normal | | show-clear-only-hover | 是否在只有 hover 的时候才显示 clear 清除按钮 | Boolean | —— | false | +| allow-number-paste | 允许type为number时可粘贴 | Boolean | —— | false | ### 事件 {page=#/input} diff --git a/src/components/input/input.vue b/src/components/input/input.vue index 05a1979..2ed1f1e 100644 --- a/src/components/input/input.vue +++ b/src/components/input/input.vue @@ -267,6 +267,10 @@ export default { showClearOnlyHover: { type: Boolean, default: false + }, + allowNumberPaste: { + type: Boolean, + default: false } }, data () { @@ -587,11 +591,14 @@ export default { const keyCode = event.keyCode const target = event.currentTarget const value = target.value + const isPaste = (event.ctrlKey || event.metaKey) && keyCode === 86 if (this.inputType === 'number') { - // 键盘按下不允许的按钮 - if (this.validKeyCodeList.indexOf(keyCode) < 0 - || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey + // 非粘贴且键盘按下不允许的按钮 + if ( + !(this.allowNumberPaste && isPaste) + && (this.validKeyCodeList.indexOf(keyCode) < 0 + || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) ) { event.stopPropagation() event.preventDefault()