import axios from "axios";

export default {
  mounted: function(e) { 
    const _this = this;
    $(document).on('draw.dt',function(e){
      $('.destroy-link').click(function(e){
          e.preventDefault();
          _this.destroy($(this).attr('href'));
      });
    });
  },
  methods: {
    destroy(href,fun=null){
      if(!confirm('Are you sure you want to delete this item?'))return false;
      axios.delete(href)
      .then(res=>{
          if(fun)
          {
            fun();
          }else{
            this.reload();
          }
          this.success();
      })
      .catch(error=>{
          this.error(error);
      });
  }
  },
}