Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access to domain name inside vue js application?

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?

like image 883
samman adhikari Avatar asked Oct 01 '20 17:10

samman adhikari


People also ask

How do I get the domain name in react JS?

To access the domain name from an above URL, we can use the window. location object that contains a hostname property which is holding the domain name. Similarly, we can also use the document. domain property to access it.

Can I use Redux with Vue?

Redux is actually view-layer agnostic, so it can easily be used with Vue via simple bindings. Vuex is different in that it knows it's in a Vue app. This allows it to better integrate with Vue, offering a more intuitive API and improved development experience.

How do I open a Vue page in JavaScript?

to open a Vue Router link in a new tab, we can call the $router. resolve method to get the full URL from the route name, path, parameter and query values. Then we can use window. open to open the URL in a new tab.

What IP addresses can my Vue JS app be accessed from?

You will not be able to access the application from your smartphone by localhost:8080, however, you will be able to do it by network IP – 192.168.1.6 in this case. In conclusion, these are the IP addresses your Vue.js can be accessed:

How can you make secure API calls from Vue JS?

How can you make secure API calls from Vue.js? Your Vue.js application authenticates the user and receives an access token from Auth0. The application can then pass that access token to your API as a credential.

How to manipulate a DOM element in Vue JS?

You can manipulate a DOM element by defining methods on the element’s reference. For example, you could focus to an input element with this: In this way, refs can be used just like the document.querySelector('.element') in JavaScript or the $('.element') in jQuery. The $refs can be accessed both inside the Vue.js instance and outside of it.

What is Vue JS?

What is Vue.js? Vue.js is a progressive JavaScript framework created by Evan You and the Vue core team with contributions from more than 230 community members. Vue is used in more than 870,000 projects and has more than 175,000 stars on GitHub. Vue.js is an approachable core library that focuses on the view layer only.


1 Answers

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.

like image 200
Igor Bykov Avatar answered Nov 02 '22 22:11

Igor Bykov