1. 组件代码:
<template>
<el-select :placeholder="placeholder" :disabled="disabled" :value="getValueSting" @change="handleInput">
<el-option
v-for="dict in dictData"
:key="dict.value"
:label="dict.lable" :value="dict.value"
></el-option>
</el-select>
</template>
<script>
import { getTableTagData } from "@/api/operation/common";
export default {
name: 'tableSelectTag',
props: {
tableName: {
type: String,
required: true
},
tableShowName: {
type: String,
required: true
},
tableShowVal: {
type: String,
required: true
},
sqlSelect: {
type: String,
required: false,
default: null
},
placeholder: String,
disabled: Boolean,
value: [String, Number],
},
computed: {
getValueSting(){
return this.value != null ? this.value.toString() : undefined;
},
},
data() {
return {
dictData: []
}
},
created() {
this.initDictData()
},
methods: {
initDictData(){
var obj = {
tableName: this.tableName,
tableShowName: this.tableShowName,
tableShowVal: this.tableShowVal,
sqlSelect: this.sqlSelect
}
getTableTagData(obj).then(res => {
this.dictData = res.data
})
},
handleInput(e='') {
let val;
if(Object.keys(e).includes('target')){
val = e.target.value
}else{
val = e
}
console.log(val);
this.$emit('change', val);
this.$emit('input', val);
},
}
}
</script>
<style scoped>
</style>
2. 使用:
<table-select-tag v-model="form.jpSb" placeholder="请选择检票设备" tableName="szpt_zygl_znsb" tableShowName="name" tableShowVal="id" sqlSelect="type=3"></table-select-tag>