Blame view

src/components/select/dropdown.vue 2.12 KB
e355dd49   梁灏   add Select Component
1
2
3
4
5
6
7
  <template>
      <div class="ivu-select-dropdown"><slot></slot></div>
  </template>
  <script>
      import Popper from 'popper.js';
  
      export default {
ab8aaf95   梁灏   add Dropdown comp...
8
9
10
11
12
13
          props: {
              placement: {
                  type: String,
                  default: 'bottom-start'
              }
          },
e355dd49   梁灏   add Select Component
14
15
16
          data () {
              return {
                  popper: null
b0893113   jingsam   :art: add eslint
17
              };
e355dd49   梁灏   add Select Component
18
19
20
21
22
23
24
25
26
27
28
          },
          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...
29
                              placement: this.placement,
e355dd49   梁灏   add Select Component
30
                              boundariesPadding: 0,
f12aca9e   梁灏   fixed #44
31
32
                              forceAbsolute: true,
                              boundariesElement: 'body'
e355dd49   梁灏   add Select Component
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
60
61
62
63
64
                          });
                          this.popper.onCreate(popper => {
                              this.resetTransformOrigin(popper);
                          });
                      });
                  }
              },
              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 }`;
              }
          },
          ready () {
              this.$on('on-update-popper', this.update);
              this.$on('on-destroy-popper', this.destroy);
          },
          beforeDestroy () {
              if (this.popper) {
                  this.popper.destroy();
              }
          }
b0893113   jingsam   :art: add eslint
65
66
      };
  </script>