Val*_*or_ 5 rest vue.js vuejs2
我在 angularJs 中有一个应用程序,$location.protocol() + '://' + $location.host()
我在处理 API 调用时使用它。
例子:
return $http({
method: 'GET',
url: $location.protocol() + '://' + $location.host() + '/rest/api/category/category',
headers: {
'Jwt-token': store.get('jwt')
}
})
Run Code Online (Sandbox Code Playgroud)
现在我正在 VUEjs 中构建另一个应用程序,我也不想使用相同的“$location”逻辑来调用 API,但我不知道如何。
我目前的实现是硬编码网址
例子:
getCategories() {
fetch(`http://myapp.test/rest/api/category/category`, {
method: 'GET'
})
.then(response => response.json())
.then(json => this.categories = json)
}
Run Code Online (Sandbox Code Playgroud)
如何将代码 ( $location.protocol() + '://' + $location.host()
) 从我的 Angular 应用程序正确地“翻译/转换”到 VueJs?如果您需要任何其他信息,请告诉我,我会提供!谢谢!
dvn*_*yen 10
使用可以在 Vue 应用程序中使用 DOM api:
document.location.protocol
用于协议document.location.host
对于当前主机document.location.origin
为了protocol+'://'+host
归档时间: |
|
查看次数: |
4641 次 |
最近记录: |