【问题标题】:How can i press the Save button repeatedly , but only save once data如何反复按保存按钮,但只保存一次数据
【发布时间】:2018-07-30 02:43:49
【问题描述】:

当我必须反复按保存按钮时,它会多次保存相同的数据。

@click="save"

 methods:{

        save(){

            }
         }
    }

我希望当我反复单击保存按钮时只能保存一个数据 到数据库。

我该怎么办? :)

【问题讨论】:

  • 最简单的方法是在第一次点击时禁用按钮。

标签: javascript vue.js vuejs2


【解决方案1】:

也许你可以试试

@click="debounce(save, 500);"

function debounce(func, wait) {
    let timer;

    return function(...args) {
        const context = this;

        clearTimeout(timer);

        timer = setTimeout(function() {
            func.apply(context, args);
        }, wait);
    };
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    相关资源
    最近更新 更多