programing

Vuejs 응용 프로그램에서 $location.protocol() 및 $location.host() 사용

javaba 2022. 7. 17. 12:23
반응형

Vuejs 응용 프로그램에서 $location.protocol() 및 $location.host() 사용

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')
    }
})

현재 VUEj에서 다른 애플리케이션을 구축하고 있으며 API 호출에 동일한 "$location" 로직을 사용하고 싶지는 않지만 방법은 알 수 없습니다.

현재 구현은 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프로토콜용
  • document.location.host현재 호스트의 경우
  • 아니면 그냥document.location.origin위해서protocol+'://'+host

언급URL : https://stackoverflow.com/questions/48022550/using-location-protocol-and-location-host-in-vuejs-application

반응형