index.js 532 B

123456789101112131415161718192021222324252627
  1. import imgPreview from './index.vue'
  2. imgPreview.install = function (Vue) {
  3. const Constructor = Vue.extend(imgPreview)
  4. let instance
  5. Vue.prototype.$showImgPreview = (imgUrl) => {
  6. if (instance) {
  7. document.body.removeChild(instance.$el)
  8. instance = null
  9. }
  10. instance = new Constructor({
  11. el: document.createElement('div'),
  12. data () {
  13. return {
  14. visible: true,
  15. imgUrl
  16. }
  17. }
  18. })
  19. document.body.appendChild(instance.$el)
  20. }
  21. }
  22. export default imgPreview