首页 > 技术文章 > 在vue中封装一个定时器

lljun 2019-07-14 20:56 原文

在main.js中进行封装
Vue.prototype.$sleep = time => {
return new Promise((resolve, reject) => {
window.setTimeout(() => {
resolve()
}, time)
})
}
这样就可以全局当中使用了。
直接$sleep(时间参数)

推荐阅读