index.vue 931 Bytes
Newer Older
张成 committed
1 2
<template>
  <el-select
lixiaomin committed
3
    v-model="selectValue"
张成 committed
4 5
    style="width: 100%"
    @change="change"
lixiaomin committed
6
    placeholder="请选择分类"
lixiaomin committed
7
    clearable
张成 committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  >
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.name"
      :value="item.id"
    >
    </el-option>
  </el-select>
</template>

<script>
import { getList } from "@/api/system/category";

export default {
  name: "Class",
  props: ["value"],
  model: {
    prop: "value",
    event: "input",
  },
  data() {
    return {
lixiaomin committed
31
      selectValue:'',
lixiaomin committed
32
      options: []
张成 committed
33 34
    };
  },
lixiaomin committed
35 36 37 38 39
  watch: {
		value(newName, oldName) {
      this.selectValue=newName;
		}
	},
张成 committed
40 41
  created() {
    this.getList();
lixiaomin committed
42
    this.selectValue=this.value;
张成 committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56
  },
  methods: {
    /** 查询列表 */
    getList() {
      getList().then((response) => {
        this.options = response.data;
      });
    },
    change(value) {
      this.$emit("input", value);
    },
  },
};
</script>