gpt4 book ai didi

rest - 在 Vuejs 应用程序中使用 $location.protocol() 和 $location.host()

转载 作者:搜寻专家 更新时间:2023-10-30 22:34:19 24 4
gpt4 key购买 nike

我在 angularJs 中有一个应用程序,我在处理 API 调用时使用 $location.protocol() + '://' + $location.host()

例子:

return $http({
method: 'GET',
url: $location.protocol() + '://' + $location.host() + '/rest/api/category/category',
headers: {
'Jwt-token': store.get('jwt')
}
})

现在我在 VUEjs 中构建另一个应用程序,我也不想使用相同的“$location”逻辑来调用 API,但我不知道如何。

我目前的实现是硬编码 url

例子:

getCategories() {
fetch(`http://myapp.test/rest/api/category/category`, {
method: 'GET'
})
.then(response => response.json())
.then(json => this.categories = json)
}

如何正确地将代码 ($location.protocol() + '://' + $location.host()) 从我的 Angular 应用程序“翻译/转换”到 VueJs?如果您需要任何其他信息,请告诉我,我会提供!谢谢!

最佳答案

使用可以在 Vue 应用程序中使用 DOM api:

  • document.location.protocol 协议(protocol)
  • 当前主机的document.location.host
  • 或者只是 document.location.origin 用于 protocol+'://'+host

关于rest - 在 Vuejs 应用程序中使用 $location.protocol() 和 $location.host(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48022550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com