Uczę się vue.js ale możliwe że tu chodzi w ogóle o działanie js
Odpalam sobie taki kodzik który ściąga dane z github api: https://vuejs.org/v2/examples/commits.html
Zagwozdkę mam w tym fragmencie
methods: {
fetchData: function () {
var xhr = new XMLHttpRequest()
var self = this
xhr.open('GET', apiURL + self.currentBranch)
xhr.onload = function () {
self.commits = JSON.parse(xhr.responseText)
console.log(self.commits[0].html_url)
}
xhr.send()
}
}
Nie rozumiem po co to var self = this
Nie możemy po prostu użyć zwykłego this?
methods: {
fetchData: function () {
var xhr = new XMLHttpRequest()
xhr.open('GET', apiURL + this.currentBranch)
xhr.onload = function () {
this.commits = JSON.parse(xhr.responseText)
console.log(this.commits[0].html_url)
}
xhr.send()
}
}
Ten kod nie działa, nie wywala błędu, ale nic się nie wyświetla