e355dd49
梁灏
add Select Component
|
1
|
<template>
|
cf753854
Sergio Crisostomo
Corrections after...
|
2
3
4
5
6
7
|
<li
:class="classes"
@click.stop="select"
@mousedown.prevent
@touchstart.prevent
><slot>{{ showLabel }}</slot></li>
|
e355dd49
梁灏
add Select Component
|
8
9
|
</template>
<script>
|
4aec6a66
梁灏
support Select
|
10
|
import Emitter from '../../mixins/emitter';
|
fed3e09d
梁灏
add AutoComplete ...
|
11
|
import { findComponentUpward } from '../../utils/assist';
|
4aec6a66
梁灏
support Select
|
12
|
|
e355dd49
梁灏
add Select Component
|
13
14
15
|
const prefixCls = 'ivu-select-item';
export default {
|
4aec6a66
梁灏
support Select
|
16
17
18
|
name: 'iOption',
componentName: 'select-item',
mixins: [ Emitter ],
|
e355dd49
梁灏
add Select Component
|
19
20
21
22
23
24
25
26
27
28
29
|
props: {
value: {
type: [String, Number],
required: true
},
label: {
type: [String, Number]
},
disabled: {
type: Boolean,
default: false
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
30
31
32
33
34
35
36
37
|
},
selected: {
type: Boolean,
default: false
},
isFocused: {
type: Boolean,
default: false
|
e355dd49
梁灏
add Select Component
|
38
39
|
}
},
|
e355dd49
梁灏
add Select Component
|
40
41
|
data () {
return {
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
42
|
searchLabel: '', // the slot value (textContent)
|
fed3e09d
梁灏
add AutoComplete ...
|
43
|
autoComplete: false
|
b0893113
jingsam
add eslint
|
44
|
};
|
e355dd49
梁灏
add Select Component
|
45
46
47
48
49
50
51
|
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-disabled`]: this.disabled,
|
fed3e09d
梁灏
add AutoComplete ...
|
52
|
[`${prefixCls}-selected`]: this.selected && !this.autoComplete,
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
53
|
[`${prefixCls}-focus`]: this.isFocused
|
e355dd49
梁灏
add Select Component
|
54
|
}
|
b0893113
jingsam
add eslint
|
55
|
];
|
e355dd49
梁灏
add Select Component
|
56
57
|
},
showLabel () {
|
b0893113
jingsam
add eslint
|
58
|
return (this.label) ? this.label : this.value;
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
59
60
|
},
optionLabel(){
|
1b39f569
Sergio Crisostomo
Use label first i...
|
61
|
return this.label || (this.$el && this.$el.textContent);
|
e355dd49
梁灏
add Select Component
|
62
63
64
65
|
}
},
methods: {
select () {
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
66
|
if (this.disabled) return false;
|
e355dd49
梁灏
add Select Component
|
67
|
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
68
69
70
71
72
73
74
75
|
this.dispatch('iSelect', 'on-select-selected', {
value: this.value,
label: this.optionLabel,
});
this.$emit('on-select-selected', {
value: this.value,
label: this.optionLabel,
});
|
e355dd49
梁灏
add Select Component
|
76
|
},
|
e355dd49
梁灏
add Select Component
|
77
|
},
|
4aec6a66
梁灏
support Select
|
78
|
mounted () {
|
fed3e09d
梁灏
add AutoComplete ...
|
79
80
|
const Select = findComponentUpward(this, 'iSelect');
if (Select) this.autoComplete = Select.autoComplete;
|
ed91d9b0
梁灏
update Select
|
81
|
},
|
b0893113
jingsam
add eslint
|
82
83
|
};
</script>
|