Vue SweetAlert (Legacy)

0.1.18 · abandoned · verified Sun Apr 19

The `vue-sweetalert` package (version 0.1.18) is an effectively abandoned JavaScript plugin designed as a demonstration for creating Vue 2 wrappers around the original, now unsupported, SweetAlert library. Last published over 9 years ago, it provides a basic `this.$swal` API for displaying simple alert dialogs within Vue 2 applications. It does not receive updates, lacks modern features, and is incompatible with Vue 3. For current projects, developers should use SweetAlert2 directly or a modern, actively maintained wrapper like `vue-sweetalert2` (by avil13), which supports both Vue 2 and Vue 3 and the actively developed SweetAlert2 library. This package serves primarily as a historical example of Vue plugin development rather than a production-ready solution.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the installation of the `vue-sweetalert` plugin in a Vue 2 application and how to trigger basic and confirm SweetAlert dialogs using `this.$swal`.

import Vue from 'vue'
import VueSweetAlert from 'vue-sweetalert'

Vue.use(VueSweetAlert)

new Vue({
  el: '#app',
  data: {},
  methods: {
    showBasicAlert() {
      this.$swal('Hello from Vue SweetAlert!')
    },
    showConfirmAlert() {
      this.$swal({
        title: 'Are you sure?',
        text: 'You will not be able to recover this imaginary file!',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: 'Yes, delete it!'
      }).then((result) => {
        if (result.value) {
          this.$swal('Deleted!', 'Your imaginary file has been deleted.', 'success')
        } else {
          this.$swal('Cancelled', 'Your imaginary file is safe :)', 'error')
        }
      })
    }
  },
  template: `
    <div id="app">
      <button @click="showBasicAlert">Show Basic Alert</button>
      <button @click="showConfirmAlert">Show Confirm Alert</button>
    </div>
  `
})

view raw JSON →