My Vue.js app structure is like so:
/app
--assets
--components
--dashboard.vue
--filters
--views
--dashboard-view.vue
app.vue
main.js
In my main.js
file I have the snippet of code below to set up vue-resource
to make HTTP requests:
Vue.use(require('vue-resource'))
Vue.http.options.root = 'http://localhost:3000/api/v1/'
Vue.http.headers.common['Authorization'] = 'Bearer ' + localStorage.getItem('authentication_token')
However, when I try to make an HTTP request in dashboard-view.vue
it doesn't listen to the configuration set in main.js
.
This is dashboard-view.vue
:
<template>
...
</template>
<script>
module.exports = {
ready: function() {
this.$http.get('/me', function(data, status, request) {
})
}
}
</script>
I'm quite new to Vue.js so help is appreciated on how to structure my app so I can easily send HTTP requests.
Thanks