-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathEditorEnumRemoteAutocomplete.vue
59 lines (56 loc) · 1.4 KB
/
EditorEnumRemoteAutocomplete.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
<el-autocomplete
v-model="showValue"
:value-key="labelfield"
:fetch-suggestions="queryModel"
v-bind="$attrs"
@select="handleSelect"
/>
</template>
<script>
import {
logError,
} from '@/widget/utility';
import _props_value_mixin from './_props_value_mixin';
import _props_label_value_mixin from './_props_label_value_mixin';
export default {
name: 'EditorEnumRemoteAutocomplete',
mixins: [
_props_value_mixin,
_props_label_value_mixin,
],
props: {
fetchSuggestions: {
type: Function,
required: true,
},
// 一般是编辑的时候 因为有了值 但是无法展示
getLabelByValue: {
type: Function,
required: true,
},
},
data () {
return {
showValue: '',
};
},
created () {
new Promise((resolve) => {
this.getLabelByValue(resolve, this.value);
}).then((showValue) => {
this.showValue = showValue;
}).catch(logError);
},
methods: {
queryModel (queryString, cb) {
// 这一层为了修正this指向
this.fetchSuggestions(cb, queryString);
},
handleSelect (item) {
this.$emit('input', item[this.valuefield]);
this.showValue = item[this.labelfield];
},
},
};
</script>