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
1 Answer
Reset to default 22You 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
版权声明:本文标题:javascript - How to access to domain name inside vue js application? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738611555a2102660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论