[Vuejs]-(Vue.js) How to use onClick event in SweetAlert2

0👍

It show, on you current HTMLDOMthere was no function defined as onClick. You have to define a function named onClick and its functionality first.

for vue:

you have to define the function inside vue instance methods.

Define target:

axios
  .get(apiUrl)
  .then(response => {
    this.$swal.fire({
      target: document.getElementById('app'),
      html: response.data.data.schools
              .map(item => `<div onclick="onClick(this)">${item.school_name}</div>`)
              .join('')
    })
  })

Leave a comment