Blame view

src/components/select/dropdown.vue 2.49 KB
e355dd49   梁灏   add Select Component
1
  <template>
8105945f   梁灏   update ColorPicker
2
      <div class="ivu-select-dropdown" :class="className" :style="styles"><slot></slot></div>
e355dd49   梁灏   add Select Component
3
4
  </template>
  <script>
a68c11a5   梁灏   support Nuxt.js
5
6
      import Vue from 'vue';
      const isServer = Vue.prototype.$isServer;
8f5b1686   梁灏   fixed #196
7
      import { getStyle } from '../../utils/assist';
130ea92a   huanghong   update popper.js
8
9
      // const Popper = isServer ? function() {} : require('popper.js');  // eslint-disable-line
      import Popper from 'popper.js';
e355dd49   梁灏   add Select Component
10
11
  
      export default {
fd1582c5   梁灏   support Menu & La...
12
          name: 'Drop',
ab8aaf95   梁灏   add Dropdown comp...
13
14
15
16
          props: {
              placement: {
                  type: String,
                  default: 'bottom-start'
8105945f   梁灏   update ColorPicker
17
18
19
              },
              className: {
                  type: String
ab8aaf95   梁灏   add Dropdown comp...
20
21
              }
          },
e355dd49   梁灏   add Select Component
22
23
          data () {
              return {
8f5b1686   梁灏   fixed #196
24
                  popper: null,
b1c118d8   梁灏   support Dropdown
25
                  width: ''
b0893113   jingsam   :art: add eslint
26
              };
e355dd49   梁灏   add Select Component
27
          },
8f5b1686   梁灏   fixed #196
28
29
30
31
32
33
34
          computed: {
              styles () {
                  let style = {};
                  if (this.width) style.width = `${this.width}px`;
                  return style;
              }
          },
e355dd49   梁灏   add Select Component
35
36
          methods: {
              update () {
a68c11a5   梁灏   support Nuxt.js
37
                  if (isServer) return;
e355dd49   梁灏   add Select Component
38
39
40
41
42
43
                  if (this.popper) {
                      this.$nextTick(() => {
                          this.popper.update();
                      });
                  } else {
                      this.$nextTick(() => {
b1c118d8   梁灏   support Dropdown
44
                          this.popper = new Popper(this.$parent.$refs.reference, this.$el, {
ab8aaf95   梁灏   add Dropdown comp...
45
                              placement: this.placement,
130ea92a   huanghong   update popper.js
46
47
48
49
50
                              modifiers: {
                                  computeStyle:{
                                      gpuAcceleration: false,
                                  }
                              }
e355dd49   梁灏   add Select Component
51
52
53
                          });
                      });
                  }
8f5b1686   梁灏   fixed #196
54
55
56
57
                  // 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
58
59
60
              },
              destroy () {
                  if (this.popper) {
e355dd49   梁灏   add Select Component
61
                      setTimeout(() => {
e845e84d   陈峰   Update dropdown.vue
62
63
64
65
                          if (this.popper) {
                              this.popper.destroy();
                              this.popper = null;
                          }
e355dd49   梁灏   add Select Component
66
67
                      }, 300);
                  }
e355dd49   梁灏   add Select Component
68
69
              }
          },
b1c118d8   梁灏   support Dropdown
70
          created () {
e355dd49   梁灏   add Select Component
71
72
73
74
75
76
77
78
              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
79
80
      };
  </script>