vue从字典中取值

定义getDic方法,加载字典

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 加载字典
// 使用时,需要
// 1、先在beforeCreate事件中先加载本页面需要使用的字典
// 例如:this.$common.getDic("DEPARTMENT"); // 部门字典
// 2、然后在调用this.$common.onDicConvent(dicType, value);
getDic: function (dicType) {
var baseUrl = "http://localhost:8765/";
var dicUrl = baseUrl + "/dic/get/" + dicType;

// 加载一些基础资源字典
if (dicType == "DEPARTMENT") dicUrl = baseUrl + "/dic/getDepartment";

if(dicType.length ==2) dicUrl = baseUrl+"/dcDic/get/"+dicType;

axios({
method: "post",
url: dicUrl,
headers: {
"content-type": "application/json;charset=UTF-8",
token: sessionStorage.getItem("authorization")
}
})
.then(res => {
if (res.data.resultCode == 500) alert("错误:加载字典失败" + res.data.message);

var json = this.getAllDic();
json.push(res.data.data);
sessionStorage.setItem("dic", JSON.stringify(json));
});

},

在需要使用字典的父页面上,添加

1
2
3
4
5
6
//1、先在beforeCreate事件中先加载本页面需要使用的字典
export default {
beforeCreate() {
this.$common.getDic("2B");
}
}

在需要使用字典的页面上

1
2
// 2、然后在调用this.$common.onDicConvent(dicType, value);
{{this.$common.onDicConvent("2B", premisesDate.dcCompany.dcCompanyFinance.classification)}}
赏个🍗吧
0%