OrgSelect.vue 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <el-select
  3. v-model="selected"
  4. class="size-select"
  5. placeholder="请选择"
  6. @change="select"
  7. style="width: 100px;"
  8. clearable
  9. >
  10. <el-option
  11. v-for="item in optionList"
  12. :key="item.id"
  13. :label="item.name"
  14. :value="item.id"
  15. >
  16. <span>{{ item.name }}</span>
  17. </el-option>
  18. </el-select>
  19. </template>
  20. <script>
  21. export default {
  22. name: "OrgSelect",
  23. props: {
  24. value: [String, Array],
  25. },
  26. data() {
  27. return {
  28. optionList: [],
  29. selected: "",
  30. };
  31. },
  32. async created() {
  33. const res = await this.$http.post("/api/admin/sys/org/query");
  34. // console.log(res.data);
  35. this.optionList = res.data.data.records;
  36. },
  37. watch: {
  38. value: {
  39. immediate: true,
  40. handler(val) {
  41. this.selected = val;
  42. },
  43. },
  44. },
  45. methods: {
  46. select() {
  47. this.$emit("input", this.selected);
  48. this.$emit("change", this.selected);
  49. },
  50. },
  51. };
  52. </script>
  53. <style></style>