[Vuejs]-How to retrieve data in nodejs from post api with vuejs

0👍

You are having a varible var self = this pointing the correct vue instancre , then why are you using this again in you callback of the vue-resource’s post request

Use self every when in the method wherever you want o reference the vue instance. This is possible due to the concept of closures.

so change your code to:

    this.$validator.validateAll().then(function(result) {
      if (result) {
        self.data = self.name;
        console.log(this.data)
        this.$http.post('/api/add_level',self.data).then(function(res){
          self.status = res.body
          console.log(self.status);
        self.largeModal=false;
        // eslint-disable-next-line
        alert('From Submitted!');


        })
        return;

      }

Note

I recommend you use normal function syntax and make use of closures or use arrow function as they bind this lexically. Do not mix them up and use simultaneously

Leave a comment