12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <template>
- <el-select v-model="newValue" placeholder="请选择">
- <el-option
- v-for="item in options"
- :key="item[valueKay]"
- :label="item.label"
- :value="item[valueKay]"
- >
- </el-option>
- </el-select>
- </template>
- <script>
- import { getList } from '@/api/dict';
- export default {
- name: 'DataSelect',
- props: {
- value: {
- type: String,
- default: ''
- },
- params: {
- type: String,
- default: ''
- },
- valueKay: {
- type: String,
- default: 'value'
- }
- },
- data() {
- return {
- newValue: this.value,
- options: []
- };
- },
- watch: {
- value: {
- handler(val) {
- this.newValue = val;
- },
- immediate: true
- },
- newValue: {
- handler(val) {
- this.$emit('input', val);
- },
- immediate: true
- }
- },
- created() {
- this.loadData();
- },
- methods: {
- async loadData() {
- const { data } = await getList({
- dictCode: this.params
- });
- this.options = data.map(x => ({
- value: x.value,
- label: x.name
- }));
- }
- }
- };
- </script>
- <style lang="scss" scoped></style>
|