element-plus input组件+select组件实现输入加选择

野性酷女 2024-04-01 18:50 163阅读 0赞

需求

用户输入数值,再选择下拉项,进行相应数据的筛选查询
在这里插入图片描述

组件select-input

  1. <template>
  2. <div>
  3. <el-input v-model="inputData" placeholder=" " clearable @clear="clear">
  4. <template #append>
  5. <el-select v-model="selectData" placeholder=" " @change="change">
  6. <el-option
  7. v-for="(item, index) in option"
  8. :key="index"
  9. :label="item.label"
  10. :value="item.value"
  11. ></el-option>
  12. </el-select>
  13. </template>
  14. </el-input>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. props: {
  20. option: {
  21. type: Array,
  22. default: [
  23. {
  24. label: "大于",
  25. value: "大于",
  26. },
  27. {
  28. label: "小于",
  29. value: "小于",
  30. },
  31. {
  32. label: "等于",
  33. value: "等于",
  34. },
  35. ],
  36. },
  37. input: {
  38. type: String,
  39. default: "",
  40. },
  41. select: {
  42. type: String,
  43. default: "",
  44. },
  45. },
  46. data() {
  47. return {
  48. selectData: "",
  49. inputData: "",
  50. }
  51. },
  52. watch: {
  53. input: {
  54. handler(val) {
  55. this.inputData = val
  56. },
  57. immediate: true,
  58. deep: true,
  59. },
  60. selectData: {
  61. handler(val) {
  62. this.selectData = val
  63. },
  64. immediate: true,
  65. deep: true,
  66. },
  67. },
  68. methods: {
  69. change() {
  70. this.$emit("update:input", this.inputData)
  71. this.$emit("update:select", this.selectData)
  72. this.$emit("change", this.inputData, this.selectData)
  73. },
  74. clear() {
  75. this.$emit("update:input", "")
  76. this.$emit("update:select", "")
  77. this.$emit("change", "", "")
  78. },
  79. },
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. :deep(.el-select) {
  84. height: 100%;
  85. .el-input__inner {
  86. display: none;
  87. }
  88. .el-tooltip__trigger {
  89. height: 100%;
  90. }
  91. .el-input__wrapper {
  92. height: 100%;
  93. }
  94. .el-input--suffix {
  95. height: 100%;
  96. }
  97. .el-input__suffix-inner > :first-child {
  98. margin-left: 0;
  99. }
  100. }
  101. :deep(.el-input) {
  102. .el-input-group__append {
  103. padding: 0 !important;
  104. .el-select {
  105. margin: 0 !important;
  106. }
  107. }
  108. }
  109. </style>

使用

  1. <select-input v-model:input="input" v-model:select="select" @change="change"></select-input>

发表评论

表情:
评论列表 (有 0 条评论,163人围观)

还没有评论,来说两句吧...

相关阅读