4
You should use origin
instead of host
:
export default {
data: function()
{
return {
localhost: window.location.origin,
};
},
}
2
window.location.host
doesn’t include the protocol:
return {
localhost: window.location.origin
}
But guessing from your problem where the API request gets "duplicated" as you said. You don’t need the localhost anyways. If you don’t specify the baseUrl (= domain/IP, port and protocol) it will automatically direct the request to localhost.
So instead of making a request to localhost/api/something
you can just do /api/something
1
window.location.host
returns url without protocol, so change it to:
return {
localhost: 'http://'+window.location.host,
}
Source:stackexchange.com