Axios get request в зависимости от пользовательских данных не работает

Я установил систему авторизации с nuxtjs & django. Однако я не понимаю nuxtjs полностью

      <template>
  <div>
     {{ this.$auth.$storage.state.user.email }}
  </div>
</template>

<script>
import axios from 'axios';
export default {
}
            axios.get('/api/v1/is-success-or-not?email='+this.$auth.$storage.state.user.email)
            .then((response) => {
            if(response.data === "True") {
            console.log("Player is success")
            $nuxt.$router.push('/schedule')
            
            }
           
            })



            axios.get('failureornot?email='+this.$auth.$storage.state.user.email)
            .then((response) => {
            if(response.data > 3) {
            console.log("failure")
            $nuxt.$router.push('/failure')
            }
            })
        </script>

Вот мой код У меня есть email, который отображается {{ this.$auth.$storage.state.user.email }}

но когда я пытаюсь адаптировать запрос get в зависимости от пользователя, я получаю эту ошибку Cannot read properties of undefined (reading '$auth')

Я не понимаю, потому что $auth явно определяется, если я могу вывести значение

спасибо за помощь!

Вам не хватает всей функции mounted в скрипте

<template>
  <div>
    {{ this.$auth.$storage.state.user.email }}
  </div>
</template>

<script>
import axios from "axios";

export default {
  mounted() {
    axios
      .get(
        "/api/v1/is-success-or-not?email=" +
          this.$auth.$storage.state.user.email
      )
      .then((response) => {
        if (response.data === "True") {
          console.log("Player is success");
          $nuxt.$router.push("/schedule");
        }
      });

    axios
      .get("failureornot?email=" + this.$auth.$storage.state.user.email)
      .then((response) => {
        if (response.data > 3) {
          console.log("failure");
          $nuxt.$router.push("/failure");
        }
      });
  },
};
</script>
Вернуться на верх