globalMixins.js 785 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { getDict } from '@/api/toConsult.js'
  2. export default {
  3. data() {
  4. return {
  5. //字典['dict_type']
  6. dicts:[]
  7. }
  8. },
  9. created() {
  10. /** 组件中设置dictType,即可获取相应的value*/
  11. if(this.dicts && this.dicts.length > 0){
  12. this.dicts.forEach(item=>{
  13. this.getDictHandler(item,(res)=>{
  14. this[item] = res
  15. })
  16. })
  17. }
  18. },
  19. methods: {
  20. //根据字典类型获取字典值
  21. getDictHandler(dictType,callBack) {
  22. getDict( dictType ).then(res => {
  23. let { code, data, msg } = res
  24. if (code == 200) {
  25. callBack(data)
  26. }
  27. })
  28. }
  29. //组件使用方法参考下边注释
  30. // this.getDictHandler('core_check_type',res=>{
  31. // console.log(res);
  32. // })
  33. }
  34. }