(VUEJS) Access the router query before injecting the services into vuejs

Asked

Viewed 28 times

2

(VUEJS) You can access the information that is sent by query on the router before injecting the services of an application?

For example:

import Vue from 'vue';
import App from './App.vue';
import router from './router';
import init from '@/services/Services';

const baseURL = 'https://api.exemplo.com.br';
let token = router.currentRoute.query.token;

const services = init(baseURL, token);
Vue.config.productionTip = false;

new Vue({
    render: h => h(App),
    router,
    provide() {
        return services;
    },
}).$mount('#app');

And when you access the address: localhost:8080/teste?token=123 he can capture the token before mounting everything?

1 answer

2

I don’t understand very well what you want to do, but follow the documentation https://br.vuejs.org/v2/api/index.html#beforeMount. If beforeMount(just before assembly starts) is the solution for what you need, you can use the this.$route.query that in which you will return {token: "123"}.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.