mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-10-31 03:22:08 +08:00 
			
		
		
		
	[bugfix] Dialog: can't show after being removed from document (#3111)
This commit is contained in:
		
							parent
							
								
									fc412ce1aa
								
							
						
					
					
						commit
						2830f4cacd
					
				| @ -4,7 +4,11 @@ import { isServer } from '../utils'; | |||||||
| 
 | 
 | ||||||
| let instance; | let instance; | ||||||
| 
 | 
 | ||||||
| const initInstance = () => { | function initInstance() { | ||||||
|  |   if (instance) { | ||||||
|  |     instance.$destroy(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   instance = new (Vue.extend(VanDialog))({ |   instance = new (Vue.extend(VanDialog))({ | ||||||
|     el: document.createElement('div'), |     el: document.createElement('div'), | ||||||
|     // avoid missing animation when first rendered
 |     // avoid missing animation when first rendered
 | ||||||
| @ -16,16 +20,16 @@ const initInstance = () => { | |||||||
|   instance.$on('input', value => { |   instance.$on('input', value => { | ||||||
|     instance.value = value; |     instance.value = value; | ||||||
|   }); |   }); | ||||||
| }; | } | ||||||
| 
 | 
 | ||||||
| const Dialog = options => { | function Dialog(options) { | ||||||
|   /* istanbul ignore if */ |   /* istanbul ignore if */ | ||||||
|   if (isServer) { |   if (isServer) { | ||||||
|     return Promise.resolve(); |     return Promise.resolve(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return new Promise((resolve, reject) => { |   return new Promise((resolve, reject) => { | ||||||
|     if (!instance) { |     if (!instance || !document.body.contains(instance.$el)) { | ||||||
|       initInstance(); |       initInstance(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -34,7 +38,7 @@ const Dialog = options => { | |||||||
|       reject |       reject | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
| }; | } | ||||||
| 
 | 
 | ||||||
| Dialog.defaultOptions = { | Dialog.defaultOptions = { | ||||||
|   value: true, |   value: true, | ||||||
| @ -79,11 +83,12 @@ Dialog.resetDefaultOptions = () => { | |||||||
|   Dialog.currentOptions = { ...Dialog.defaultOptions }; |   Dialog.currentOptions = { ...Dialog.defaultOptions }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | Dialog.resetDefaultOptions(); | ||||||
|  | 
 | ||||||
| Dialog.install = () => { | Dialog.install = () => { | ||||||
|   Vue.use(VanDialog); |   Vue.use(VanDialog); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| Vue.prototype.$dialog = Dialog; | Vue.prototype.$dialog = Dialog; | ||||||
| Dialog.resetDefaultOptions(); |  | ||||||
| 
 | 
 | ||||||
| export default Dialog; | export default Dialog; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user