Uncaught TypeError: this.$once is not a function?

        this.$once("hook: updated", function() {})

this.$once应该是被vue3中删除了,现在想达到这种效果要怎么修改?
提示错误:
Uncaught TypeError: this.$once is not a function?

阅读 2.9k
1 个回答

自己实现一个once也不复杂。

function once(fn) {
    let isCall = false;
    return (...args) => !isCall && (isCall = true) && fn.apply(null, args)
}

this.$on('event', once(function() {
 // TODO
}))
推荐问题