Vue.js wrapper for SweetAlert2.
// vue-component.vue
<template>
<button @click="showAlert">Hello world</button>
<button @click="showAlertWithComponent('hello')">Hello world, again</button>
<button @click="showAlertWithComponent2('hello')">Hello world, another time</button>
</template>
<script>
import anotherVueComponent from 'another-vue-component.vue'
export default {
methods: {
showAlert(){
this.$swal.fire({
type: 'success',
title: 'Hello world',
text: 'hi from swal-vue',
})
},
showAlertWithComponent(message){
this.$swal.fire({
type: 'success',
title: 'Hello world',
text: 'hi from swal-vue',
component: anotherVueComponent,
componentArgs: {propsData: {msg: message}}
})
const component = this.$swal.getComponent()
},
showAlertWithComponent2(message){
this.$swal.fire({
type: 'success',
title: 'Hello world',
text: 'hi from swal-vue',
})
this.$swal.addVueComponent(anotherVueComponent, {propsData: {msg: message}})
const component = this.$swal.getComponent()
}
}
}
</script>