{"action":"created","issue":{"url":"https://api.github.com/repos/vuejs/vue-resource/issues/229","repository_url":"https://api.github.com/repos/vuejs/vue-resource","labels_url":"https://api.github.com/repos/vuejs/vue-resource/issues/229/labels{/name}","comments_url":"https://api.github.com/repos/vuejs/vue-resource/issues/229/comments","events_url":"https://api.github.com/repos/vuejs/vue-resource/issues/229/events","html_url":"https://github.com/vuejs/vue-resource/issues/229","id":137929512,"number":229,"title":"Access current Vue instance through Global scope.","user":{"login":"ionutvelicu","id":2823654,"avatar_url":"https://avatars.githubusercontent.com/u/2823654?v=3","gravatar_id":"","url":"https://api.github.com/users/ionutvelicu","html_url":"https://github.com/ionutvelicu","followers_url":"https://api.github.com/users/ionutvelicu/followers","following_url":"https://api.github.com/users/ionutvelicu/following{/other_user}","gists_url":"https://api.github.com/users/ionutvelicu/gists{/gist_id}","starred_url":"https://api.github.com/users/ionutvelicu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ionutvelicu/subscriptions","organizations_url":"https://api.github.com/users/ionutvelicu/orgs","repos_url":"https://api.github.com/users/ionutvelicu/repos","events_url":"https://api.github.com/users/ionutvelicu/events{/privacy}","received_events_url":"https://api.github.com/users/ionutvelicu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-02T16:52:21Z","updated_at":"2016-03-07T10:56:19Z","closed_at":"2016-03-05T13:22:51Z","body":"Hello!\r\n\r\nI am used to split my code as follows in order to have some basic separation of concerns:\r\n\r\n- I am creating a service module:\r\n```\r\nvar Vue = require('vue')\r\n\r\nmodule.exports.save function(name) {\r\n  return Vue.http.post('/foo/', {\r\n    name: name\r\n  });\r\n}\r\n```\r\n\r\n- Then, from my VM / Controller I am using this as follows:\r\n```\r\nvar service = require('./service/foo-service')\r\nvar app= new Vue({\r\n  data : {\r\n    foos: [],\r\n  },\r\n  methods : {\r\n    save: function(name) {\r\n      service.save(name).then(function(resp) {\r\n        this.foos.push(resp.foo)\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\nSince the `$http.post` is decoupled and called globally, the `this` from the callback is pointing to the `window` object. Of course, this doesn't happen if the resource is called from the method itself.\r\n\r\nIs there a way to access the current Vue instance while working with the global version of the http service? If not, is there a best practice / preferred way to decouple service calls from the component / VM logic?\r\n\r\nGreat work with this project!\r\nThank you!"},"comment":{"url":"https://api.github.com/repos/vuejs/vue-resource/issues/comments/193203309","html_url":"https://github.com/vuejs/vue-resource/issues/229#issuecomment-193203309","issue_url":"https://api.github.com/repos/vuejs/vue-resource/issues/229","id":193203309,"user":{"login":"ionutvelicu","id":2823654,"avatar_url":"https://avatars.githubusercontent.com/u/2823654?v=3","gravatar_id":"","url":"https://api.github.com/users/ionutvelicu","html_url":"https://github.com/ionutvelicu","followers_url":"https://api.github.com/users/ionutvelicu/followers","following_url":"https://api.github.com/users/ionutvelicu/following{/other_user}","gists_url":"https://api.github.com/users/ionutvelicu/gists{/gist_id}","starred_url":"https://api.github.com/users/ionutvelicu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ionutvelicu/subscriptions","organizations_url":"https://api.github.com/users/ionutvelicu/orgs","repos_url":"https://api.github.com/users/ionutvelicu/repos","events_url":"https://api.github.com/users/ionutvelicu/events{/privacy}","received_events_url":"https://api.github.com/users/ionutvelicu/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T10:56:19Z","updated_at":"2016-03-07T10:56:19Z","body":"Great point @steffans! Thanks for your help & effort!"}}