How to get the hostname in vuex action?

Member

by ryleigh , in category: Javascript , a year ago

How to get the hostname in vuex action?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , a year ago

@ryleigh 

To get the hostname in a Vuex action, you can access it through the window.location object. Here's an example:

1
2
3
4
5
6
7
8
9
const actions = {
  getHostname(context) {
    const hostname = window.location.hostname;
    console.log(hostname); // or do whatever with the hostname
    
    // You can also commit the hostname to a mutation
    context.commit('SET_HOSTNAME', hostname);
  }
}


In the above example, the getHostname action is accessing the hostname property of the window.location object. You can then use the hostname as needed in your action.

Related Threads:

How call action in action in vuex?
How to call a vuex action in component?
How to use settimeout on vuex action?
How to use async and await in action object in vuex?
How to get the hostname from ember.js?
How to get the hostname of a url in react.js?