The use of vue setTimeout() calling method and not calling method

Don't call method

handleRun () {
    
    
	setTimeout(function () {
    
    
    	console.log('谢谢')
  	}, 3000)  // 3秒后执行
}

Call method

show () {
    
    
	console.log('谢谢')
}handleRun () {
    
    
	//注意this.show加括号和不加括号的区别
 	setTimeout(this.show(), 3000) // 直接执行无延时
 	setTimeout(this.show, 3000) // 3秒后执行
}

Transfer parameters

show (params) {
    
    
	console.log(params)
},
handleRun () {
    
    
 	setTimeout(this.show, 3000, '谢谢') // 把“谢谢”传给show方法,3秒后执行
}

Guess you like

Origin blog.csdn.net/weixin_43908123/article/details/108594545