Blame view

src/components/loading-bar/loading-bar.js 1.09 KB
9dde24b6   梁灏   add LoadingBar co...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  import LoadingBar from './loading-bar.vue';
  import Vue from 'vue';
  import { camelcaseToHyphen } from '../../utils/assist';
  
  LoadingBar.newInstance = properties => {
      const _props = properties || {};
  
      let props = '';
      Object.keys(_props).forEach(prop => {
          props += ' :' + camelcaseToHyphen(prop) + '=' + prop;
      });
  
      const div = document.createElement('div');
      div.innerHTML = `<loading-bar${props}></loading-bar>`;
      document.body.appendChild(div);
  
      const loading_bar = new Vue({
          el: div,
          data: _props,
          components: { LoadingBar }
      }).$children[0];
  
      return {
          update (options) {
              if ('percent' in options) {
                  loading_bar.percent = options.percent;
              }
              if (options.status) {
                  loading_bar.status = options.status;
              }
              if ('show' in options) {
                  loading_bar.show = options.show;
              }
          },
          component: loading_bar,
          destroy () {
              document.body.removeChild(div);
          }
b0893113   jingsam   :art: add eslint
39
      };
9dde24b6   梁灏   add LoadingBar co...
40
41
42
  };
  
  export default LoadingBar;