K
K
krispey2021-08-20 16:57:44
Vue.js
krispey, 2021-08-20 16:57:44

Vue js how to send axios on click to any place on the page?

It is necessary that if the user clicked on any place on the page, the axios request for the php file worked. I didn’t understand how to make axios send on click, but I only did it so that axios worked when the page loaded. How can I make it work on click?

data() {
    return {
      info: ''
    }
  },
  mounted() {
      axios
          .get(url + '/lk_src/checkAuth.php')
          .then(response => {
            this.info = response.data;
            console.log(this.info);
            if (this.info == 'NoAuthorization') {
              this.$store.dispatch('auth/logout').catch(()=>{});
              this.$router.push('/login').catch(()=>{});
            }
          })
  },

//тут типо должен быть обработчик клика на странице, но как вызвать axios по нему, так и не понял
document.addEventListener("click", function() {

});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-08-20
@krispey

What prevents a handler from being hung in mounted?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question