StdSelectOption.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <a-select
  3. v-model="tempValue"
  4. :defaultValue="Object.keys(options)[0]"
  5. @change="$emit('change', isNaN(parseInt(tempValue)) || keyType === 'string' ? tempValue : parseInt(tempValue) )">
  6. <a-select-option v-for="(v,k) in options" :key="k">{{ v }}</a-select-option>
  7. </a-select>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'StdSelectOption',
  12. props: {
  13. value: [Number, String, Boolean],
  14. options: [Array, Object],
  15. keyType: {
  16. type: String,
  17. default() {
  18. return 'int'
  19. }
  20. }
  21. },
  22. model: {
  23. prop: 'value',
  24. event: 'change'
  25. },
  26. data() {
  27. return {
  28. tempValue: null
  29. }
  30. },
  31. watch: {
  32. value() {
  33. this.tempValue = this.value != null ? this.value.toString() : null
  34. }
  35. },
  36. created() {
  37. this.tempValue = this.value != null ? this.value.toString() : null
  38. }
  39. }
  40. </script>
  41. <style lang="less" scoped>
  42. .ant-select {
  43. min-width: 80px;
  44. }
  45. </style>