Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Setting ...options.root on a vue instance, using router params #718

Open
Miguel-Frazao opened this issue Jan 26, 2019 · 0 comments
Open

Comments

@Miguel-Frazao
Copy link

Miguel-Frazao commented Jan 26, 2019

I have something like this on my main.js before Vue instatiation:

if(typeof localStorage.lang === 'undefined')
	lang = 'pt';
else {
	if(localStorage.lang === 'pt')
		lang = 'pt';
	else
		lang = 'en';
}

Vue.http.options.root = 'http://127.0.0.1:8000/api/webapp/' +lang;

On my router:

export default new Router({
  routes: [
    {
      {
          path: ':lang/foo',
          component: {
            ....
          },
       }
    }
 ]});

And I am trying to do something like this on my main component App.vue:

export default {
  name: 'app',
  watch: {
    '$route.params.lang': function(new_val, old_val) { // ex: new_val is now en
      this.$http.options.root = 'http://127.0.0.1:8000/api/webapp/' +new_val; <-- trying to change root endpoint
      localStorage.setItem('lang', new_val);
      console.log(new_val); // en
      console.log(localStorage.lang); // en
      console.log(this.$http.options.root); // http://127.0.0.1:8000/api/webapp/pt <-- doesn't change
    }
  }
};

I need to change the root endpoint for the api, or an alternative not far from this simple implementation.

@Miguel-Frazao Miguel-Frazao changed the title Setting Vue.http.options.root on a vue instance Setting Vue.http.options.root on a vue instance, using router params Jan 26, 2019
@Miguel-Frazao Miguel-Frazao changed the title Setting Vue.http.options.root on a vue instance, using router params Setting ...options.root on a vue instance, using router params Jan 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant