ValueModify.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div class="value-modify">
  3. <el-select
  4. v-if="available.options && available.options.length"
  5. v-model="inputValue"
  6. clearable
  7. @change="valChange"
  8. >
  9. <el-option
  10. v-for="item in available.options"
  11. :key="item"
  12. :value="item"
  13. :label="item"
  14. >
  15. </el-option>
  16. </el-select>
  17. <el-input-number
  18. v-else-if="available.type === 'number'"
  19. v-model="inputValue"
  20. :controls="false"
  21. @change="valChange"
  22. ></el-input-number>
  23. <el-switch
  24. v-else-if="available.type === 'boolean'"
  25. v-model="inputValue"
  26. active-color="#13ce66"
  27. inactive-color="#ff4949"
  28. @change="valChange"
  29. >
  30. </el-switch>
  31. <el-input
  32. v-else
  33. v-model="inputValue"
  34. :maxlength="500"
  35. @input="valChange"
  36. ></el-input>
  37. </div>
  38. </template>
  39. <script>
  40. export default {
  41. name: "value-modify",
  42. props: {
  43. value: {
  44. type: [String, Number, Boolean, Array],
  45. default: null
  46. },
  47. available: {
  48. type: Object,
  49. default() {
  50. return {
  51. type: "string",
  52. defaultValue: "",
  53. options: []
  54. };
  55. }
  56. }
  57. },
  58. data() {
  59. return {
  60. inputValue: null
  61. };
  62. },
  63. watch: {
  64. value: {
  65. immediate: true,
  66. handler(val) {
  67. this.inputValue = val;
  68. }
  69. }
  70. },
  71. methods: {
  72. valChange() {
  73. this.$emit("input", this.inputValue);
  74. this.$emit("change", this.inputValue);
  75. }
  76. }
  77. };
  78. </script>