a5654a65c63c9e55ce154d4ca4dec8952f2e0786.svn-base 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <el-select clearable v-model="value" placeholder="请选择">
  3. <el-option
  4. v-for="item in options"
  5. :key="item.key"
  6. :label="item.value"
  7. :value="item.key">
  8. </el-option>
  9. </el-select>
  10. </template>
  11. <script>
  12. /*
  13. 组件名称:elSelectWithDict
  14. 组件用途:结合字典逻辑的下拉选择列表
  15. 包含组件:(无))
  16. 包含API文件:
  17. (util.gw_dictionary -获取字典数据的通用方法类)
  18. props:dictId - 指定字典代码
  19. value - 绑定值
  20. 版本记录:
  21. 0.0.1 (初版) @author:wxcwater @date:2018.09.11
  22. 0.0.2 (增加说明) @author:wxcwater @date:2018.09.16
  23. */
  24. import {getdictItemBydictIdSync,getDictKeyByDictIdAndValueSync,getDictValueByDictIdAndKeySync} from '../utils/gw_dictionary.js';
  25. export default {
  26. props: ['dictId','initialValue'],
  27. data() {
  28. return {
  29. options:[],
  30. value: '',
  31. key: '',
  32. descr: ''
  33. }
  34. },
  35. computed:{
  36. },
  37. watch: {
  38. value:function(val){
  39. let key = getDictKeyByDictIdAndValueSync(this.dictId,val);
  40. this.$emit('input', key);
  41. },
  42. descr:function(val){
  43. let value = getDictValueByDictIdAndKeySync(this.dictId,val);
  44. this.$emit('input', value);
  45. },
  46. },
  47. methods:{
  48. getOptions:function(){
  49. let _self = this;
  50. _self.options = getdictItemBydictIdSync(this.dictId);
  51. // getdictItemBydictIdSync(this.dictId).then(
  52. // function (res) {
  53. // _self.options = res;
  54. // console.log(res);
  55. // }
  56. // );
  57. }
  58. },
  59. mounted(){
  60. this.value = this.initialValue;
  61. console.log(this.initialValue)
  62. this.getOptions();
  63. }
  64. }
  65. </script>
  66. <style>
  67. </style>