主页

Promise

Promise和async-await转化 // async格式 async function async1() { console.log(111) await async2() console.log(222) } async function async2() { console.log(333) } // 转Promise格式 function asyncs() { console.log(111) new Promise(resolve=> { console.log(333) resolve() }).then(()=>{ conso...

阅读更多

element-ui

关于弹窗和消息提示的单独引用 main.js中 // Message的引用 import { Message} from "element-ui" Message.install = function (Vue, options) { Vue.prototype.$message = Message Vue.use(Message) } // MessageBox的引用 import { MessageBox } from "element-ui" Vue.prototype.$messageBox = MessageBox // MessageBox的使用 this.$messageBox.confirm('确定要退出注册嘛?', '提示', { ...

阅读更多

JavaScript常用方法

数组去重 // 双层for循环去重 function deWeight(Arr) { for (let i = 0; i < Arr.length; i++) { for (let j = i+1; j < Arr.length; j++ ) { if (Arr[i] === Arr[j]) { Arr.splice(j, 1) j--; } } } return Arr; } //indexOf去重 function deWeight(Arr) { if (!Array...

阅读更多

JavaScript事件原理

事件循环(消息循环) 事件循环是基于浏览器主线程的 Js是一门单线程语言,其执行在浏览器的主线程上 浏览器不是只有单线程的 Js若所有程序都在一个线程上执行,则浏览器必然会发生阻塞现象,故而有异步执行来解决Js的单线程同步问题 换一个角度来说,Js是一门基于浏览器的多线程语言 主线程的Js代码执行会影响页面的渲染 => 主线程上执行延时死循环时,只有其循环结束后才会执行其他代码,包括对页面的渲染工作 浏览器的任务没有优先级先后之说,但是执行过程中产生的不同的任务队列却有优先级先后 任务队列分为宏任务和微任务,而宏任务因为不能满足浏览器的任务安排需求,故而又被分解成很多其他任务...

阅读更多