javascript - vueJS,超时不等待计时器

标签 javascript vue.js

我正在尝试在 vue.JS 中设置一个简单的超时,但不知何故,等待时间似乎不起作用,因为我的 parse 函数是立即触发的,而不是 5 秒后触发

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)
    }
}

最佳答案

您正在调用this.parse(url) 但你需要传递函数 https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

          this.typingTimer = setTimeout(
           () => this.parse(url),
            this.doneTypingInterval
        );

关于javascript - vueJS,超时不等待计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55777378/

相关文章:

javascript - 根据媒体查询更改 window.scroll 位置?

javascript - 'resolve' 的 Expo webpack 配置不起作用

javascript - 在 WordPress 中的其他页面内容之前加载 div

ruby-on-rails - Rails 5.2 使用 Axios 请求返回 406

vue.js - VueJS - 传单 - GeoJSON - RangeError : Maximum call stack size exceeded

javascript - 在 :value of <option> tag in vuejs 中使用 split()

javascript - Cesium Earth实体路径质量

javascript - Lerna 能否根据 Conventional Commits 规范提升预发布版本?

javascript - 聊天应用程序的自下而上布局设计

vue.js - 如何在v-for中获取键、值和索引