I have one application in angularJs where I use $location.protocol() + '://' + $location.host()
when I'm dealing with API calls.
Example:
return $http({
method: 'GET',
url: $location.protocol() + '://' + $location.host() + '/rest/api/category/category',
headers: {
'Jwt-token': store.get('jwt')
}
})
Now I'm building another application in VUEjs and i also wan't to use same "$location" logic to call API, but I don't know how.
My current implementation is hardcoding url
Example:
getCategories() {
fetch(`http://myapp.test/rest/api/category/category`, {
method: 'GET'
})
.then(response => response.json())
.then(json => this.categories = json)
}
How to properly "translate/convert" the code ($location.protocol() + '://' + $location.host()
) from my Angular app to VueJs? If you need any additional information's please let me know and I will provide! Thank you!
Use can use the DOM api inside Vue applications:
document.location.protocol
for protocoldocument.location.host
for the current hostdocument.location.origin
for protocol+'://'+host
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With