Search code examples
vue.jssweetalert2

referencing images in SweetAlert2 modals in vue


I have a sweetAlert2 modal and I wanted to use an image inside it but either I reference an img like this src="./assets/img/cry.png" or src="../assets/img/cry.png" it will not show up but in other parts of vue this src addresses works fine, how should I reference it in SweetAlert2?

 this.$swal({
 title: '<div style="font-weight:bold;">sorry</div>',
 icon: 'error',
 confirmButtonText: 'Cool',
 position: 'top',
 backdrop: false,
 html:'<img  src="../assets/img/cry.png" style="width:128px;height:128px;">',
 })

enter image description here


Solution

  • it is solved like this:

    const imagePath = require("@/assets/img/cry.png");
    
    this.$swal({
    title: '<div style="font-weight:bold;">sorry</div>',
    showConfirmButton: false,
    backdrop: false,
    imageUrl: imagePath,
    imageWidth: 100,
    imageHeight: 100,
    });