select.vue 796 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <el-select v-model="newValue" v-bind="props" multiple @change="onChange">
  3. <el-option
  4. v-for="(item, index) in list"
  5. :value="item.id"
  6. :label="item.name"
  7. :key="index"
  8. ></el-option>
  9. </el-select>
  10. </template>
  11. <script>
  12. export default {
  13. name: "cl-role-select",
  14. props: {
  15. value: [String, Number, Array],
  16. props: Object
  17. },
  18. data() {
  19. return {
  20. list: [],
  21. newValue: undefined
  22. };
  23. },
  24. watch: {
  25. value: {
  26. immediate: true,
  27. handler(val) {
  28. let arr = [];
  29. if (!(val instanceof Array)) {
  30. arr = [val];
  31. } else {
  32. arr = val;
  33. }
  34. this.newValue = arr.filter(Boolean);
  35. }
  36. }
  37. },
  38. async created() {
  39. this.list = await this.$service.system.role.list();
  40. },
  41. methods: {
  42. onChange(val) {
  43. this.$emit("input", val);
  44. }
  45. }
  46. };
  47. </script>