globalMixins.js 820 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. computed:{
  20. //根据字典类型获取字典值,返回字典label
  21. getDicts(s,dict){
  22. return this[dict].find(v=> s == v.dictValue).dictLabel;
  23. },
  24. },
  25. methods: {
  26. //根据字典类型获取字典值
  27. getDictHandler(dictType,callBack) {
  28. getDict( dictType ).then(res => {
  29. let { code, data, msg } = res
  30. if (code == 200) {
  31. callBack(data)
  32. }
  33. })
  34. },
  35. }
  36. }