e355dd49
梁灏
add Select Component
|
1
|
<template>
|
8f5b1686
梁灏
fixed #196
|
2
|
<div class="ivu-select-dropdown" :style="styles"><slot></slot></div>
|
e355dd49
梁灏
add Select Component
|
3
4
|
</template>
<script>
|
8f5b1686
梁灏
fixed #196
|
5
|
import { getStyle } from '../../utils/assist';
|
e355dd49
梁灏
add Select Component
|
6
7
8
|
import Popper from 'popper.js';
export default {
|
ab8aaf95
梁灏
add Dropdown comp...
|
9
10
11
12
13
14
|
props: {
placement: {
type: String,
default: 'bottom-start'
}
},
|
e355dd49
梁灏
add Select Component
|
15
16
|
data () {
return {
|
8f5b1686
梁灏
fixed #196
|
17
18
|
popper: null,
width: '',
|
b0893113
jingsam
add eslint
|
19
|
};
|
e355dd49
梁灏
add Select Component
|
20
|
},
|
8f5b1686
梁灏
fixed #196
|
21
22
23
24
25
26
27
|
computed: {
styles () {
let style = {};
if (this.width) style.width = `${this.width}px`;
return style;
}
},
|
e355dd49
梁灏
add Select Component
|
28
29
30
31
32
33
34
35
36
37
|
methods: {
update () {
if (this.popper) {
this.$nextTick(() => {
this.popper.update();
});
} else {
this.$nextTick(() => {
this.popper = new Popper(this.$parent.$els.reference, this.$el, {
gpuAcceleration: false,
|
ab8aaf95
梁灏
add Dropdown comp...
|
38
|
placement: this.placement,
|
e355dd49
梁灏
add Select Component
|
39
|
boundariesPadding: 0,
|
f12aca9e
梁灏
fixed #44
|
40
41
|
forceAbsolute: true,
boundariesElement: 'body'
|
e355dd49
梁灏
add Select Component
|
42
43
44
45
46
47
|
});
this.popper.onCreate(popper => {
this.resetTransformOrigin(popper);
});
});
}
|
8f5b1686
梁灏
fixed #196
|
48
49
50
51
|
// set a height for parent is Modal and Select's width is 100%
if (this.$parent.$options.name === 'iSelect') {
this.width = parseInt(getStyle(this.$parent.$el, 'width'));
}
|
e355dd49
梁灏
add Select Component
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
},
destroy () {
if (this.popper) {
this.resetTransformOrigin(this.popper);
setTimeout(() => {
this.popper.destroy();
this.popper = null;
}, 300);
}
},
resetTransformOrigin(popper) {
let placementMap = {top: 'bottom', bottom: 'top'};
let placement = popper._popper.getAttribute('x-placement').split('-')[0];
let origin = placementMap[placement];
popper._popper.style.transformOrigin = `center ${ origin }`;
}
},
|
b89a982e
梁灏
fixed #205
|
69
|
compiled () {
|
e355dd49
梁灏
add Select Component
|
70
71
72
73
74
75
76
77
|
this.$on('on-update-popper', this.update);
this.$on('on-destroy-popper', this.destroy);
},
beforeDestroy () {
if (this.popper) {
this.popper.destroy();
}
}
|
b0893113
jingsam
add eslint
|
78
79
|
};
</script>
|