Select.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="wrap">
  3. <Select
  4. class="select"
  5. :value="value"
  6. :options="options"
  7. @focus="onFocus"
  8. @change="onChange"
  9. @blur="onBlur"
  10. />
  11. <span>{{ reactData.tip }}</span>
  12. </div>
  13. </template>
  14. <script lang="ts">
  15. import { Select } from 'ant-design-vue';
  16. import { defineComponent, reactive, toRefs } from 'vue';
  17. const props = {
  18. value: { type: String, default: '' },
  19. tip: { type: String, default: '' },
  20. options: { type: Array, default: [] },
  21. };
  22. export default defineComponent({
  23. components: { Select },
  24. props,
  25. emits: ['change'],
  26. setup(props, { emit }) {
  27. const reactData = reactive({
  28. tip: '',
  29. });
  30. function onFocus() {
  31. reactData.tip = props.tip;
  32. }
  33. function onBlur() {
  34. reactData.tip = '';
  35. }
  36. function onChange(val) {
  37. emit('change', val);
  38. }
  39. return {
  40. onFocus,
  41. onBlur,
  42. onChange,
  43. reactData,
  44. ...toRefs(props),
  45. };
  46. },
  47. });
  48. </script>
  49. <style scoped>
  50. .wrap {
  51. display: flex;
  52. }
  53. .select {
  54. width: 55%;
  55. margin-right: 10px;
  56. }
  57. span {
  58. font-size: 13px;
  59. line-height: 250%;
  60. color: gray;
  61. }
  62. </style>