This commit is contained in:
dqjdda
2019-11-21 09:11:17 +08:00
parent 01e003d9f1
commit 1c88d57f04
3 changed files with 2 additions and 173 deletions

View File

@@ -1,41 +0,0 @@
import { get, getDictMap } from '@/api/dictDetail'
export default {
data() {
return {
dicts: [], dictMap: {}
}
},
methods: {
async getDict(name) {
return new Promise((resolve, reject) => {
get(name).then(res => {
this.dicts = res.content
resolve(res)
}).catch(err => {
reject(err)
})
})
},
// 多个字典查询时使用逗号拼接, 如:
// 加载多个数据字典,如何调用如下:
// this.getDict('user_status,job_status')
// 在vue中使用加载出来的字典
// dictMap.[字典名称] 如dictMap.user_status、 dictMap.job_status
async getDictMap(names) {
// 优先放入到dictMap中避免页面加载时 undefined
const arr = names.split(',')
for (let i = 0; i < arr.length; i++) {
this.dictMap[arr[i]] = []
}
return new Promise((resolve, reject) => {
getDictMap(names).then(res => {
this.dictMap = res
resolve(res)
}).catch(err => {
reject(err)
})
})
}
}
}