I have an application in Vue.js, and in it there is an App.vue like this:
<template> <div id="app"> <router-view/> </div> </template> <script> export default { name: 'App', data() { return { user: null, } }, methods: { getUser() { axios .get(`auth/user/`) .then(response => { this.user=response.data.pk }) } }, beforeMount() { this.getUser(); }, } </script>
Can I access user variables from other components somehow? How should I export and import it successfully?
$root.someVariable
Works in Vue 2, not tested in 3.
you can:
users
to a shared state solution such as Vuex or Pinia