admin管理员组

文章数量:1201362

I have a fullstack MEVN project which I am trying to host. One problem that I am facing is that when I was running the project locally I had hard coded the url to the node server inside my vue js code to make server requests. But now since I have merged the front and back end together for web hosting, my frontend needs to access the Base url(domain name) of the server it is being hosted in so that It can make api request to the same domain name. I could hard code the domain name in vue project before deploying it but there must be a way to look into the domain name inside the application itself. How may I do so?

I have a fullstack MEVN project which I am trying to host. One problem that I am facing is that when I was running the project locally I had hard coded the url to the node server inside my vue js code to make server requests. But now since I have merged the front and back end together for web hosting, my frontend needs to access the Base url(domain name) of the server it is being hosted in so that It can make api request to the same domain name. I could hard code the domain name in vue project before deploying it but there must be a way to look into the domain name inside the application itself. How may I do so?

Share Improve this question asked Oct 1, 2020 at 17:28 samman adhikarisamman adhikari 6512 gold badges12 silver badges22 bronze badges 2
  • are you using vue router? – Boussadjra Brahim Commented Oct 1, 2020 at 17:34
  • 2 you would access it like you would in any vanilla JS application. window object is available to any vue application. – Justin Duncan Commented Oct 1, 2020 at 19:09
Add a comment  | 

1 Answer 1

Reset to default 22

You may use window.location built-in object, particularly window.location.origin or maybe window.location.host looks particularly similar to what you are looking for.

本文标签: javascriptHow to access to domain name inside vue js applicationStack Overflow