index.js 736 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. let dom = null
  2. async function asyncConstructor (Vue, comp) {
  3. if (!comp) {
  4. let component = await import('./index.vue')
  5. comp = Vue.extend(component.default)
  6. return comp
  7. }
  8. return comp
  9. }
  10. let imgPreview = {}
  11. imgPreview.install = function (Vue) {
  12. let instance
  13. Vue.prototype.$showImgPreview = async (imgUrl) => {
  14. let Constructor = await asyncConstructor(Vue, dom)
  15. if (instance) {
  16. document.body.removeChild(instance.$el)
  17. instance = null
  18. }
  19. instance = new Constructor({
  20. el: document.createElement('div'),
  21. data () {
  22. return {
  23. visible: true,
  24. imgUrl
  25. }
  26. }
  27. })
  28. document.body.appendChild(instance.$el)
  29. }
  30. }
  31. export default imgPreview