Javascript Vuejs Sweetalert未捕获类型错误

Javascript Vuejs Sweetalert未捕获类型错误,javascript,vue.js,Javascript,Vue.js,我有Uncaught TypeError:this.fetchReports不是一个函数错误,当调用函数this.fetchReports时,我似乎可以从swal对象访问该函数,如何使该函数成为全局函数?我正在使用Vuejs和SweetAlert,这是我的代码 methods: { fetchReports: function () { this.$http.get('/reports/vueGetRequest', function (reports) { this.$

我有
Uncaught TypeError:this.fetchReports不是一个函数
错误,当调用函数
this.fetchReports
时,我似乎可以从swal对象访问该函数,如何使该函数成为全局函数?我正在使用Vuejs和SweetAlert,这是我的代码

methods: {
  fetchReports: function () {
    this.$http.get('/reports/vueGetRequest', function (reports) {
      this.$set('reports', reports);
      //this.reports = reports;
    })
  },
  sortBy: function (ordenarpor) {
    this.reverso = (this.ordenarpor == ordenarpor) ? !this.reverso : false;
    this.ordenarpor = ordenarpor;
  },
  //Borrar usuario
  borrarUsuario: function (id) {
    // this.initial.id = 'borrar_confirmation';
    // this.initial.appendChild(this.texto_confirmation);
    // this.container = this.initial.textContent;
    // this.container = this.initial.id;

    swal({
      title: "Desea borrarlo?",
      text: "Una vez borrado no se podra recuperar",
      type: "warning",
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: 'si',
      closeOnConfirm: false
    }, function (isConfirm) {
      //swal("Eliminado!", "Ha sido eliminado exitosamente!!", "success");
      if (isConfirm) {
        //this.$http.post('/reports/vueGetRequest' , id);
        Vue.http.post('/reports/vueGetRequest', id);
        // refresh the page una vez eliminado
        this.fetchReports();
        swal("Eliminado!", "Ha sido eliminado correctamente!!.", "success");
      } else {
        swal("Cancelado", "Cancelado :)", "error");
      }
    });
  }
}

您的问题是swal回调函数中的
this
的值

您可以尝试以下方法:

borrarUsuario: function (id) {
  var self = this; // <------

  swal({
    title: "Desea borrarlo?",
    text: "Una vez borrado no se podra recuperar",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: 'si',
    closeOnConfirm: false
  }, function (isConfirm) {
    if (isConfirm) {
      Vue.http.post('/reports/vueGetRequest', id);
      self.fetchReports(); // <------
      swal("Eliminado!", "Ha sido eliminado correctamente!!.", "success");
    } else {
      swal("Cancelado", "Cancelado :)", "error");
    }
  });
}
borrarusario:function(id){

var self=this;//可以使用实例变量调用Vuejs实例中的任何函数

var vm=new Vue({
   el:'#app',
   data:{},
   methods: {
      fetchReports:function(){
      //do your stuff
    }
   }
});

//Outside in javascript file you can call

  vm.fetchReports();

非常感谢您的帮助,它对我很有用:)。
var vm=new Vue({
   el:'#app',
   data:{},
   methods: {
      fetchReports:function(){
      //do your stuff
    }
   }
});

//Outside in javascript file you can call

  vm.fetchReports();