[Vuejs]-How do I get my delete function to work in Vue JS?

0👍

a tag is using GET-request and you need DELETE-request. Use button and a handler in which you can use some package like axios or got to make such requests (and other GET, POST, PUT).

<button
  class="btn btn-light btn-small"
  onclick="onDelete">
  <i class="bi bi-trash"></i>
  Delete
</button>
<script>
import axios from 'axios';

export default {
  methods: {
    async onDelete() {
      if(!confirm('Are you sure you want to delete this entry?') {
        return
      }
      await axios.delete(`/delete/${this.id}`);
    },
    alertID(id) {
      this.$router.push({
        path: `/modify/${id}`,
      });
    },
  },
};
</script> 

Leave a comment