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