在vue中封装一个定时器

在main.js中进行封装
Vue.prototype.$sleep = time => {
return new Promise((resolve, reject) => {
window.setTimeout(() => {
resolve()
}, time)
})
}
这样就可以全局当中使用了。
直接$sleep(时间参数)
原文地址:https://www.cnblogs.com/lljun/p/11185649.html