index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <!-- 数字输入框 value也是number-->
  3. <u-input v-bind="__attrs" v-on="__listeners" ref="uInput">
  4. <template slot="prefix">
  5. <slot name="prefix"></slot>
  6. </template>
  7. <template slot="suffix">
  8. <slot name="suffix"></slot>
  9. </template>
  10. </u-input>
  11. </template>
  12. <script>
  13. import uProps from 'uview-ui/components/u-input/props';
  14. export default {
  15. name: 'cInputNumber',
  16. model: {
  17. prop: 'value',
  18. event: 'input',
  19. },
  20. props: {
  21. ...uProps.props,
  22. type: {
  23. default: 'number',
  24. type: String,
  25. },
  26. },
  27. computed: {
  28. __attrs() {
  29. return {
  30. ...this.$props,
  31. ...this.$attrs,
  32. placeholder: this.$props.placeholder || '请输入',
  33. };
  34. },
  35. __listeners() {
  36. return {
  37. ...this.$listeners,
  38. input: this.onInput,
  39. blur: this.onBlur,
  40. change: this.onChange,
  41. };
  42. },
  43. },
  44. methods: {
  45. onChange(val) {
  46. let numVal = val;
  47. if (this.type === 'number' && val) {
  48. numVal = +val; // 转number
  49. }
  50. this.$emit('change', numVal);
  51. },
  52. onInput(val) {
  53. let numVal = val;
  54. if (this.type === 'number' && val) {
  55. numVal = +val; // 转number
  56. }
  57. this.$emit('input', numVal);
  58. },
  59. onBlur(val) {
  60. let numVal = val;
  61. if (this.type === 'number' && val) {
  62. numVal = +val; // 转number
  63. }
  64. this.$emit('blur', numVal);
  65. },
  66. },
  67. };
  68. </script>