Hakan Gundogan
Hakan Gundogan

Reputation: 277

vue js setTimeout in created method

    methods: {

        showAlert() {
            alert("alert");
        }

    },

    created() {
        setTimeout(this.showAlert(), 5000)
    }

My codes are in here. I want to set time out in created area. But browser does not see setTimeout. it always runs when the page renders. Its not waiting. How to fix that problem?

Upvotes: 1

Views: 443

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

run the method inside the setTimeout callback like :

 created() {
        setTimeout(()=>{
        this.showAlert()
         }, 5000)
    }

Upvotes: 2

Related Questions