测试加载loding效果的方法
作者:互联网
//1.普通方法
function delay(time) {
new Promise(resolve => {
setTimeout(() => {
resolve()
}, time)
})
}
await delay(2000)
console.log('test')
//2.箭头函数方法
const delay = (time) => new Promise(resolve => setTimeout(() => resolve(), time))
await delay(2000)
//3.舍弃函数封装与自定义时长,最精简写法
(async () => {
await new Promise(r => setTimeout(() => r(), 2000)) // 一行代码
console.log('test')
})()
/** vue中的用法 */
main.js全局挂载
vue.prototype.$delay = (t) => new Promise(r => setTimeout(() => r(), t))
await this.$delay(2000)
标签:resolve,await,delay,2000,loding,测试,new,setTimeout,加载 来源: https://blog.csdn.net/weixin_43323913/article/details/120797400