0

I am trying to setup a simple timeout in vue.JS but somehow it seems that the waiting time is not working as my parse function is triggered immediately instead of 5 seconds later

props: {
        url:String
    },
    data(){
        return{
            typingTimer:null,
            doneTypingInterval: 5000
        }
    },
methods: {
        parseTimeout(url){
            clearTimeout(this.typingTimer);
            this.typingTimer = setTimeout(
                this.parse(url),
                this.doneTypingInterval
            );
        },
        parse(url){
           console.log('triggered')
        },
},
watch: {
    url(){
        this.parseTimeout(this.$props.url)
    }
}

1 Answer 1

3

You are calling this.parse(url) but you need to pass function https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

          this.typingTimer = setTimeout(
           () => this.parse(url),
            this.doneTypingInterval
        );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.