Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuejs - On input, run a function (but with a delay)

I have an input field, and v-on:input it runs a method called activate that looks like this:

export default: {
    data() {
        return {
            isHidden: true
        }
    },
    methods: {
        activate() {
            this.isHidden = false;
        }
    }
}

isHidden turns on/off some icon (it doesn't really matter what this data property is; I'm just using it for example purposes).

So currently, when a user does an input it immediately turns on the activate function. Is there a way to, perhaps, put it on a delay via setTimeout? I've tried doing the following but it doesn't work:

methods: {
    setTimeout(function() {
        activate() {
            this.isHidden = false;
        }
    }, 500)
}
like image 562
MonkeyOnARock Avatar asked Feb 28 '17 14:02

MonkeyOnARock


1 Answers

Try this:

methods: {
  activate() {
    setTimeout(() => this.isHidden = false, 500);
  }
}
like image 71
Joe Attardi Avatar answered Oct 11 '22 12:10

Joe Attardi