@@ -38,7 +38,7 @@ export default class VueWait {
3838 }
3939
4040 init ( Vue , store ) {
41- if ( nodeIsDebug ( ) && ! install . installed ) {
41+ if ( nodeIsDebug ( ) && ! install . installed && VueWait . getVueVersion ( Vue ) < 3 ) {
4242 console . warn (
4343 `[vue-wait] not installed. Make sure to call \`Vue.use(VueWait)\` before init root instance.`
4444 ) ;
@@ -67,16 +67,25 @@ export default class VueWait {
6767 store . registerModule ( vuexModuleName , vuexStore ) ;
6868 }
6969
70- this . stateHandler = new Vue ( {
70+ const config = {
7171 computed : {
7272 is : ( ) => waiter => store . getters [ `${ vuexModuleName } /is` ] ( waiter ) ,
7373 any : ( ) => store . getters [ `${ vuexModuleName } /any` ] ,
7474 percent : ( ) => waiter =>
7575 store . getters [ `${ vuexModuleName } /percent` ] ( waiter )
7676 }
77- } ) ;
77+ } ;
78+
79+ if ( VueWait . getVueVersion ( Vue ) > 2 ) {
80+ const { createApp } = require ( 'vue' ) ;
81+ this . stateHandler = createApp ( config ) . mount (
82+ document . createElement ( 'div' )
83+ ) ;
84+ } else {
85+ this . stateHandler = new Vue ( config ) ;
86+ }
7887 } else {
79- this . stateHandler = new Vue ( {
88+ const config = {
8089 data ( ) {
8190 return {
8291 waitingFor : [ ] ,
@@ -106,7 +115,16 @@ export default class VueWait {
106115 this . progresses = progress ( this . progresses , waiter , current , total ) ;
107116 }
108117 }
109- } ) ;
118+ } ;
119+
120+ if ( VueWait . getVueVersion ( Vue ) > 2 ) {
121+ const { createApp } = require ( 'vue' ) ;
122+ this . stateHandler = createApp ( config ) . mount (
123+ document . createElement ( 'div' )
124+ ) ;
125+ } else {
126+ this . stateHandler = new Vue ( config ) ;
127+ }
110128 }
111129
112130 this . initialized = true ;
@@ -116,6 +134,10 @@ export default class VueWait {
116134 return this . stateHandler . any ;
117135 }
118136
137+ static getVueVersion ( app ) {
138+ return parseFloat ( ( app . version || '' ) . split ( '.' ) [ 0 ] || 0 ) ;
139+ }
140+
119141 is ( waiter ) {
120142 return this . stateHandler . is ( waiter ) ;
121143 }
@@ -208,7 +230,34 @@ export function install(Vue) {
208230 install . installed = true ;
209231}
210232
233+ function createVueWait ( options ) {
234+ const Wait = {
235+ async install ( app ) {
236+ if ( this . installed && app ) {
237+ if ( nodeIsDebug ( ) ) {
238+ console . warn ( '[vue-wait] already installed' ) ;
239+ }
240+ return ;
241+ }
242+
243+ const instance = new VueWait ( options ) ;
244+ instance . init ( app , app . config . globalProperties . $store ) ;
245+ app . config . globalProperties [ instance . options . accessorName ] = instance ;
246+
247+ app . mixin ( {
248+ beforeCreate ( ) {
249+ this . __$waitInstance = instance ;
250+ }
251+ } ) ;
252+
253+ this . installed = true ;
254+ }
255+ } ;
256+
257+ return Wait ;
258+ }
259+
211260// Export which are imported to export
212- export { mapWaitingActions , mapWaitingGetters , waitFor } ;
261+ export { mapWaitingActions , mapWaitingGetters , waitFor , createVueWait } ;
213262
214263VueWait . install = install ;
0 commit comments