59
loading...
This website collects cookies to deliver better user experience
npm install -g @vue/cli
vue create vue-sweetalert && cd vue-sweetalert
import Vue from 'vue'
import VueSweetalert2 from 'vue-sweetalert2';
import App from './App.vue';
Vue.use(VueSweetalert2);
new Vue({
el: '#app',
render: h => h(App)
});
<template>
<!-- button used to trigger event -->
<button v-on:click="sweetAlert">Click me</button>
</template>
<script>
export default {
data() {
return {
text: ''
}
},
methods: {
sweetAlert() {
this.$swal('Heading', 'this is a Heading', 'OK');
}
}
}
<script>
<template>
<button v-on:click="sweetAlert">Click Me!</button>
</template>
<script>
export default {
data() {
return {}
},
methods: {
sweetAlert() {
this.$swal({
title: 'What is your Name?',
input: 'text',
inputPlaceholder: 'Enter your name here',
showCloseButton: true,
});
}
}
}
</script>
<template>
<button v-on:click="sweetAlert">Click Me!</button>
</template>
<script>
export default {
data() {
return {}
},
methods: {
sweetAlert() {
this.$swal({
title: '<i>Custom HTML</i>',
html:`This is an <em> emaphazied text </em>, <a href="#">links</a><strong>And other tags</strong>`,
showCloseButton: true,
showCancelButton: true,
focusConfirm: false,
})
}
}
}
</script>
<template>
<button v-on:click="sweetAlert">Click Me!</button>
</template>
<script>
export default {
data() {
return {}
},
methods: {
sweetAlert() {
this.$swal({
title: 'Are you sure?',
text: 'You can\'t revert your action',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes Delete it!',
cancelButtonText: 'No, Keep it!',
showCloseButton: true,
showLoaderOnConfirm: true
}).then((result) => {
if(result.value) {
this.$swal('Deleted', 'You successfully deleted this file', 'success')
} else {
this.$swal('Cancelled', 'Your file is still intact', 'info')
}
})
}
}
}
</script>