Reputation: 255
Actually I wan't to set up the default url so I am not typing the same url again and again. Here is my main.js :
import Vue from 'vue'
import App from './App.vue'
import VueResource from 'vue-resource'
Vue.use(VueResource)
Vue.http.options.root = 'http://localhost:8085'
new Vue({
el: '#app',
render: h => h(App)
})
Then in my component I Write methods like this :
getData: function () {
alert('masuk sini');
this.$http.get('/api/datageneration/environment')
.then((response) => {
return response.json();
}).then((data) => {
console.log(data);
this.lists = data.content;
});
}
I run it on port 8082 using command npm run dev
but why when I call the methods, it always aim to port 8082? I already set up the root for port 8085 where my back end running.
Upvotes: 0
Views: 1613
Reputation: 5486
The configuration documentation for vue-resource states:
Note that for the root option to work, the path of the request must be relative. This will use this the root option:
Vue.http.get('someUrl')
while this will not:Vue.http.get('/someUrl')
.
So, try to remove the leading /
in your call to the api:
this.$http.get('api/datageneration/environment')
Upvotes: 3