0
的問題是,我無法訪問set
方法:
this.$get = function($http) {
return
{
set: function(UserData)
{
this.user = UserData ;
localStorage.setItem('user', JSON.stringify(UserData));
},
get: function()
{
return this.user;
},
send: function(data)
{
$http.post(BASE_URL + 'user/login', data)
.then(function(res){
// Error !
this.set(res.data);
console.log(this); // return window object
// Here i want to access to 'this.set()'
// but i get error: 'ypeError: this.set is not a function'
});
}
}
}
我要尋找的解決方案來訪問this.set()
謝謝!
爲什麼不嘗試後前一個變量權分配「這個」,然後使用該變量的回調。 – ronster37