S
S
slagoris2021-08-05 13:34:09
Vue.js
slagoris, 2021-08-05 13:34:09

How to setTimeout in Vue?

Hello. Do not judge strictly, I'm at the very beginning of learning vue, but in a combat project.
There is a Home.vue main page. There was a button that calls the method that opens the modal

methods: {
            showFirstModal() {
                this.$store.commit("showModal", {
                    name: "сallToRegistrationModal",
                    props: null,
                    isShown: true,
                });
            },
    }

Now, the button is removed. And the Method needs to be launched similarly with setTimeout 20 seconds after the component is created. But I don't understand how to do it. Looks like I screwed up, but it doesn't work. They advised using the mounted hook, but I didn’t figure out how, because. has not yet reached the hooks in the study.
Tell me, plz.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
veryoriginalnickname, 2021-08-05
@slagoris

mounted() {
    setTimeout(() =>{
      this.showFirstModal()
    }, 20000)
  },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question