Commit 24c8f4eaba6250092d30f0c7b2282a3a7f5797e6
1 parent
dd28e57f
LoadingBar support SSR
Showing
1 changed file
with
13 additions
and
14 deletions
Show diff stats
src/components/loading-bar/loading-bar.js
1 | 1 | import LoadingBar from './loading-bar.vue'; |
2 | 2 | import Vue from 'vue'; |
3 | -import { camelcaseToHyphen } from '../../utils/assist'; | |
4 | 3 | |
5 | 4 | LoadingBar.newInstance = properties => { |
6 | 5 | const _props = properties || {}; |
7 | 6 | |
8 | - let props = ''; | |
9 | - Object.keys(_props).forEach(prop => { | |
10 | - props += ' :' + camelcaseToHyphen(prop) + '=' + prop; | |
7 | + const Instance = new Vue({ | |
8 | + data: _props, | |
9 | + render (h) { | |
10 | + return h(LoadingBar, { | |
11 | + props: _props | |
12 | + }); | |
13 | + } | |
11 | 14 | }); |
12 | 15 | |
13 | - const div = document.createElement('div'); | |
14 | - div.innerHTML = `<loading-bar${props}></loading-bar>`; | |
15 | - document.body.appendChild(div); | |
16 | - | |
17 | - const loading_bar = new Vue({ | |
18 | - el: div, | |
19 | - data: _props, | |
20 | - components: { LoadingBar } | |
21 | - }).$children[0]; | |
16 | + const component = Instance.$mount(); | |
17 | + document.body.appendChild(component.$el); | |
18 | + const loading_bar = Instance.$children[0]; | |
22 | 19 | |
23 | 20 | return { |
24 | 21 | update (options) { |
... | ... | @@ -34,7 +31,9 @@ LoadingBar.newInstance = properties => { |
34 | 31 | }, |
35 | 32 | component: loading_bar, |
36 | 33 | destroy () { |
37 | - document.body.removeChild(div); | |
34 | + setTimeout(function() { | |
35 | + document.body.removeChild(document.getElementsByClassName('ivu-loading-bar')[0].parentElement); | |
36 | + }, 500); | |
38 | 37 | } |
39 | 38 | }; |
40 | 39 | }; | ... | ... |