| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <template>
- <el-select clearable v-model="value" placeholder="请选择">
- <el-option
- v-for="item in options"
- :key="item.key"
- :label="item.value"
- :value="item.key">
- </el-option>
- </el-select>
- </template>
- <script>
- /*
- 组件名称:elSelectWithDict
- 组件用途:结合字典逻辑的下拉选择列表
- 包含组件:(无))
- 包含API文件:
- (util.gw_dictionary -获取字典数据的通用方法类)
- props:dictId - 指定字典代码
- value - 绑定值
- 版本记录:
- 0.0.1 (初版) @author:wxcwater @date:2018.09.11
- 0.0.2 (增加说明) @author:wxcwater @date:2018.09.16
- */
- import {getdictItemBydictIdSync,getDictKeyByDictIdAndValueSync,getDictValueByDictIdAndKeySync} from '../utils/gw_dictionary.js';
- export default {
- props: ['dictId','initialValue'],
- data() {
- return {
- options:[],
- value: '',
- key: '',
- descr: ''
- }
- },
- computed:{
-
- },
- watch: {
- value:function(val){
- let key = getDictKeyByDictIdAndValueSync(this.dictId,val);
- this.$emit('input', key);
- },
- descr:function(val){
- let value = getDictValueByDictIdAndKeySync(this.dictId,val);
- this.$emit('input', value);
- },
- },
- methods:{
- getOptions:function(){
- let _self = this;
- _self.options = getdictItemBydictIdSync(this.dictId);
- // getdictItemBydictIdSync(this.dictId).then(
- // function (res) {
- // _self.options = res;
- // console.log(res);
- // }
- // );
- }
- },
- mounted(){
- this.value = this.initialValue;
- console.log(this.initialValue)
- this.getOptions();
- }
- }
- </script>
- <style>
- </style>
|