如何在 Vue.js 方法中使用 setTimeout()
函数?
我已经尝试过这样的事情,但它不起作用:
fetchHole: function () {
//get data
},
addHole: function () {
//my query add new
setTimeout(function () { this.fetchHole() }, 1000)
},
我收到此错误消息: Uncaught TypeError: this.fetchHole is not a function
原文由 user3757488 发布,翻译遵循 CC BY-SA 4.0 许可协议
试试这个:
setTimeout(this.fetchHole, 1000)
因为匿名函数中的this
附加到该匿名函数而不是主函数