0

I'm learning VueJS and I figure out the usage of this in some cases. By example: to access some atribute in the data().

But, I tried to call a method inside another method and was doing nothing because I wasn't using this to call the other method. Can someone explain the more detailed the general and in this case usage of this?

methods:{
    sendData(){
        this.$http.post('FIREBASE-LINK/data.json', this.user).then(response=>{
            console.log(response)
            this.getData()
        }).catch(err=>{
            console.log(err)
        })
    },
    getData: function () {
        this.$http.get('FIREBASE-LINK/data.json').then(resp=>{
            this.users = resp.body
        }).catch(err=>{
            console.log(err)
        })
    }
}
Itchydon
  • 2,293
  • 5
  • 16
  • 30
Gustavo Dias
  • 95
  • 5
  • 12
  • 1
    does [this](https://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) help – Jaromanda X Aug 19 '17 at 23:25
  • To properly understand the usage of `this` in a Vue setting requires a very strong understanding of how `this` works in a typical JavaScript environment, specifically how functions like `call`, `apply` and `bind` work as that is how Vue achieves access to members of multiple blocks of data (`data`, `methods`, `computed`) through `this`. It is not something you will be able to properly understand from anything anyone could write in an answer here, but something you will learn over time as you use JavaScript and Vue. – Marty Aug 19 '17 at 23:29
  • To expand upon what @marty said, vue implements its own $http methods that will be in context when your `method` object is in execution context. Although I have not used vue myself. – kaushik94 Aug 19 '17 at 23:31
  • @kaushik94 Methods that start with a `$` denote plugin methods (or inbuilt Vue instance methods) - in this case from the vue-resource plugin :-) On that note, Evan has officially stated that vue-resource will no longer be maintained and to use an AJAX library like axios instead. – Marty Aug 19 '17 at 23:47

0 Answers0