RuoYi-Vue 使用字典
定义数据:
export default {
name: "Tests",
data() {
return {
// 数据字典
typeOptions: [],
获取字典值:
created() {
this.getList();
this.getDicts("supplies_type").then(response => {
this.typeOptions = response.data;
});
},
字典翻译:
methods: {
// 字典翻译
typeFormat(row, column) {
return this.selectDictLabel(this.typeOptions, row.type);
},
字典选取:
<el-form-item label="类型" prop="type">
<el-select
v-model="queryParams.type"
placeholder="物料类型"
clearable
size="small"
style="width: 240px"
>
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
字典回显:
<el-table-column prop="type" label="物料类型" :formatter="typeFormat" width="100"></el-table-column>